[C#]Farbcode in einem Pixel

01/01/2012 19:14 BlendedMed#1
hey ich möchte den farbcode in einem pixel bekommen und habe folgendes versucht:

Code:
[...]
using System.Threading;

namespace WindowsFormsApplication41
{
    public partial class Form1 : Form
    {
        public int Yreihe = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Thread.Sleep(4000);
            Bitmap bmp = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
                                    System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            Yreihe = MousePosition.Y;

            for (int i = 400; i < 900; i++)
            {
                Color pixelColor = bmp.GetPixel(i, Yreihe);
                if (pixelColor.ToString() != "Color [A=0, R=0, G=0, B=0]")
                {
                    MessageBox.Show(pixelColor.ToString());
                }
            }
        }
    }
}
jedoch finde ich auf diese methode keine farben in der reihe pixel.
gibt es nicht ein befehl wo man auf den bitmap verzichten könnte?

mfg
sixkay
01/01/2012 19:32 MoepMeep#2
Dir ist aber schon bewußt, dass jeder Pixel in bmp die Farbe (0,0,0) hat, oder? ;o
01/01/2012 19:37 BlendedMed#3
Quote:
Originally Posted by MoepMeep View Post
Dir ist aber schon bewußt, dass jeder Pixel in bmp die Farbe (0,0,0) hat, oder? ;o
ah mist
kenn mich mit pixelsearch noch nicht aus aber wie soll ich es dann schreiben?
01/01/2012 19:42 MoepMeep#4
Wenn du schon so einen pixelseach crap machen willst, dann mach halt einen Screenshot und lad ihn in bmp.
01/01/2012 19:44 BlendedMed#5
Quote:
Originally Posted by MoepMeep View Post
Wenn du schon so einen pixelseach crap machen willst, dann mach halt einen Screenshot und lad ihn in bmp.
ne ist für game da soll eine bestimmte reihe von pixeln nach einer bestimmten farbe abgesucht werden.
01/01/2012 19:47 MoepMeep#6
Quote:
Originally Posted by Sixkay View Post
ne ist für game da soll eine bestimmte reihe von pixeln nach einer bestimmten farbe abgesucht werden.
Und? Verfahren ist das gleiche, lol.
01/01/2012 19:49 BlendedMed#7
Quote:
Originally Posted by MoepMeep View Post
Und? Verfahren ist das gleiche, lol.
jede milli sec ein bild zu machen und ein pixel suchen ist nicht das wahre
01/01/2012 19:51 MoepMeep#8
Quote:
Originally Posted by Sixkay View Post
jede milli sec ein bild zu machen und ein pixel suchen ist nicht das wahre
Und wieso willst du dann unbedingt pixelsearch nutzen? :>
01/01/2012 19:54 BlendedMed#9
Quote:
Originally Posted by MoepMeep View Post
Und wieso willst du dann unbedingt pixelsearch nutzen? :>
weil man nicht umbedingt ein bild absuchen muss sondern auch den bildschirm nach einer farbe überprüfen kann
01/01/2012 19:56 MoepMeep#10
Quote:
Originally Posted by Sixkay View Post
weil man nicht umbedingt ein bild absuchen muss sondern auch den bildschirm nach einer farbe überprüfen kann
Wenn du doch weißt wie es geht, wieso fragst du dann?
01/01/2012 19:59 BlendedMed#11
Quote:
Originally Posted by MoepMeep View Post
Wenn du doch weißt wie es geht, wieso fragst du dann?
ich kenne die nötigen befehle leider nicht
ich danke dir trozdem
01/01/2012 20:01 MoepMeep#12
Na, dann sag das doch.
[Only registered and activated users can see links. Click Here To Register...]
01/01/2012 20:33 BlendedMed#13
habs raus

für leute die später auch das prob haben und hier rein schauen:
Code:
  using System.Runtime.InteropServices;

  sealed class Win32
  {
      [DllImport("user32.dll")]
      static extern IntPtr GetDC(IntPtr hwnd);

      [DllImport("user32.dll")]
      static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);

      [DllImport("gdi32.dll")]
      static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);

      static public System.Drawing.Color GetPixelColor(int x, int y)
      {
       IntPtr hdc = GetDC(IntPtr.Zero);
       uint pixel = GetPixel(hdc, x, y);
       ReleaseDC(IntPtr.Zero, hdc);
       Color color = Color.FromArgb((int)(pixel & 0x000000FF),
                    (int)(pixel & 0x0000FF00) >> 8,
                    (int)(pixel & 0x00FF0000) >> 16);
       return color;
      }
von: [Only registered and activated users can see links. Click Here To Register...]

#close pls