Hallo!
Dies ist mein erster Post hier auf dieser Seite, ich hoffe also dass ich mich im richtigen Forum befinde
Zu meinem Problem:
Ich bin dabei eine Funtkion zu schreiben, mit der ich die Farben (R, G, und B Wert als int) eines Pixels (x, y) auslese.
Bis jetzt bin ich so weit:
Header:
...
SDL_Surface *m_pBitmap;
Uint8 r, g, b;
SDL_PixelFormat *format;
...
Funktionen:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
void GetRGB()
{
m_pBitmap = new SDL_Surface();
m_pBitmap = SDL_LoadBMP ("Data/Bild.bmp");
if (m_pBitmap != NULL)
cout << "Bitmap wurde geladen" << endl;
SDL_LockSurface (m_pBitmap);
format = new SDL_PixelFormat;format = m_pBitmap->format; Uint32 pixel = get_pixel32(m_pBitmap, 0, 0);
SDL_GetRGB(pixel, format, &r, &g, &b);
cout << "Rot: " << (int)(r) << " Grün: " << (int)(g) << " Blau: " << (int)(b) << endl;
cout << "BytesPerPixel: " << (int) m_pBitmap->format->BytesPerPixel;
cout << endl;
SDL_UnlockSurface (m_pBitmap);
}
Uint32 get_pixel32( SDL_Surface *surface, int x, int y )
{
//Convert the pixels to 32 bit
Uint32 *pixels = (Uint32 *)surface->pixels;
//Get the requested pixel
return pixels[ ( y * surface->w ) + x ];
}
|
Die erste habe ich selbst geschrieben, die zweite von Lazy Foo.
Mein Problem ist nun, dass das Programm abstürzt, wenn diese Zeile aufgerufen wird:
SDL_GetRGB(pixel, format, &r, &g, &b);
Wäre nett, wenn mir jemand sagen kann, woran das liegt.
Wenn ich irgend welche Informationen vergessen haben sollte, einfach Schreiben
Gruß,
4I_Fr3d0