?
Hallo,
Ich will in C# von einem Windowhandle einzelne Pixel auslesen. GetPixel/SetPixel ist zu langsam.
Für LockBits muss ich wohl ein Bitmap erzeugen, was auch wieder lange dauert. Außerdem wüsste ich nicht wie ich Lockbits direkt auf ein Windowhandle anwenden könnte.
Daher kam mir die Idee mit GedDIBits. Leider erhalte ich immer ein Byte Array voller Nullen(0) zurück.
Folgender Code wird verwendet:
int DIB_RGB_COLORS = 0;
// prepare DCs, bitmaps,..
IntPtr hdcSrc = WindowManagement.User32.GetWindowDC(Handle);
IntPtr hmemDC = GDI32.CreateCompatibleDC(hdcSrc); //hdcDest
IntPtr hmemBM = GDI32.CreateCompatibleBitmap(hdcSrc, Width, Heigth); //hBitmap
GDI32.SelectObject(hmemDC, hmemBM);
// copy screen to memory DC
GDI32.BitBlt(hmemDC, 0, 0, Width, Heigth, hdcSrc, 0, 0, GDI32.SRCCOPY);
// where the bytes are
byte[] bBytes = new byte[Width * Heigth * 3];
// fill .bmp - structures
BITMAPINFO bmInfo = new BITMAPINFO();
bmInfo.bmiHeader.biSize = 40;
bmInfo.bmiHeader.biWidth = Width;
bmInfo.bmiHeader.biHeight = Heigth;
bmInfo.bmiHeader.biPlanes = 1;
bmInfo.bmiHeader.biBitCount = 16;
bmInfo.bmiHeader.biCompression = 0;
bmInfo.bmiHeader.biSizeImage = 0;
bmInfo.bmiHeader.biXPelsPerMeter = 0;
bmInfo.bmiHeader.biYPelsPerMeter = 0;
bmInfo.bmiHeader.biClrUsed = 0;
bmInfo.bmiHeader.biClrImportant = 0;
// copy bitmap data into global memory
GDI32.GetDIBits(hmemDC, hmemBM, 0, Heigth, bBytes, bmInfo.bmiHeader, DIB_RGB_COLORS);
// clean up
GDI32.DeleteDC(hmemDC);
GDI32.DeleteObject(hmemBM);
Was mache ich falsch? Geht GetDIBits unter WinXP mit 32 bit Farbe gar nichts?
Verzweifelte Grüße,
DerVerzweifelte