Scanline Problem
-
Hallo,
ich hab ein eigenartiges Problem. Ich gab einem Freund ein Programm zum Testen. Er bekam an einer Stelle ein Zugriffsverletzung. Zum Nachforschen hab ich meine Auflösung geändert, da das Problem scheinbar auf 16:9 zurückzuführen war. Unter nicht 4:3 Auflösung bekam ich den gleichen Fehler bei mir auch. Komischerweise kommt er nun auch wenn ich wieder bei 4:3 bin. Hier mal der Minimal-Code:
struct RGBTriple { BYTE rgbtBlue; BYTE rgbtGreen; BYTE rgbtRed; BYTE unknown; }; Graphics::TBitmap screenshot = new Graphics::TBitmap(); screenshot->PixelFormat = pf24bit; //Screenshot machen TCanvas *canvas = new TCanvas(); canvas->Handle = GetWindowDC(GetDesktopWindow()); TRect source; GetWindowRect(GetDesktopWindow(),(LPRECT)&source); screenshot->Width = source.Right; screenshot->Height = source.Bottom; screenshot->Canvas->CopyRect(screenshot->Canvas->ClipRect,canvas,source); //Screenshot Ende RGBTriple *ptr; for(int y = 0; y < screenshot->Height; y++) //Height = 1024 { ptr = reinterpret_cast<RGBTriple*>(screenshot->ScanLine[y]); for(int x = 0; x < screenshot->Width-7; x++) //Width = 1280 { try { int r = ptr[x].rgbtRed; //hier krachts bei mir bei x = 960 } catch(...) { ShowMessage(x); } } }
Das komische ist, dass ich zum Testen meine Auflösung auf 1280x800 gesetzt hatte und nicht auf 1280x960. Auf meinem EEEPC knallt es an der Stelle sobald 768 erreicht ist, passt also auch irgendwie in das Auflösungsschema. Ich verstehe an der Stelle nicht, warum er meckert, da die Scanline ja 1280 Einheiten "breit" ist. Weiß jemand Rat?
greetz KN4CK3R
-
Hallo,
warum hast du in der struct RGBTriple 4 Byte bei einem screenshot->PixelFormat = pf24bit;?
-
hallo,
danke für den Tipp. Bevor ich die Screenshot-Funktion hatte, habe ich die Bilddaten aus dem Zwischenspeicher geladen und entweder hatte da das Format dann 24bit oder die Funktion LoadFromClipboard hat das Pixelformat automatisch selbst geändert. Mit pf32bit funktioniert es auf jeden Fall wieder richitg.
greetz KN4CK3R