Probleme avec getpixel

SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013 - 12 juin 2004 à 12:09
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013 - 16 juin 2004 à 11:29
Bonjour tout le monde !!
Voila g voulu modifier une fonction !!
void test (HBITMAP hBmp) {
if (!hBmp) return 0;
........
DC hdcc = NULL;
hdcc = CreateCompatibleDC(NULL);
SelectObject(hdcc, hBmp);
.........
for (int y = 0; y < bm.bmHeight; y++)
{
for (int x = 0; x < bm.bmWidth; x++)
{
int x0 = x;
while (x < bm.bmWidth)
{
char chaine[5];
itoa(GetPixel(hdcc,x, y),chaine,10);
MessageBox (NULL, chaine, "ee", MB_OK);
if(GetPixel(hdcc,x, y) == RGB(0,0,0) )
x++;

............
et la fonction getpixel me retourne toujour -1 ???
G vu que ca voulait dire ke je me trouvais hors des limites mais je ne voit pas trop ou j'ai fait l'erreur !!

4 réponses

SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
12 juin 2004 à 17:20
G trouvé l'erreur mais pas la solution !!
En fait Le HDC se fait mal !!
HDC hdcc = NULL;
hdcc = CreateCompatibleDC(NULL);
if (hdcc == NULL) { MessageBox (NULL, "erreur0","ee", MB_OK); }
if (SelectObject(hdcc, hBmp) == NULL) { MessageBox (NULL, "erreur1","ee", MB_OK); }
En faisant ca j'ai la boite de dialogue erreur1 !!
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
13 juin 2004 à 21:12
J'ai essayé avec une autre methode

BITMAP bm;
GetObject(hBmp, sizeof(bm), &bm); // met les infos d'en tete du bitmap dans bm

BITMAPINFO bi;
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = bm.bmWidth;
bi.bmiHeader.biHeight = bm.bmHeight;
bi.bmiHeader.biPlanes = bm.bmPlanes;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;

DWORD dwWidthBytes = 4*((3*bm.bmWidth+3)/4);
DWORD dwImageSize = dwWidthBytes*bm.bmHeight;
LPBYTE lpBits = new BYTE[dwImageSize];

HDC hdc = GetDC(NULL);
int testt = GetDIBits(hdc, hBmp, 0, bm.bmHeight, &lpBits, &bi, DIB_RGB_COLORS);

Et j'ai un autre probleme avec la fonction GetDIBits : parametre incorect !!

Help !!!
0
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
14 juin 2004 à 21:15
pour la création du DC compatible, utilise celui de l'écran :
HDC hScreenDC = GetDC(NULL);
HDC hdc = CreateCompatibleDC(hScreenDC);
..

le reste comme ta première solutions

solution avec getDiBbits : donner directement lpBits et pas l'adresse de cette variable :
GetDIBits(hdc, hBmp, 0, bm.bmHeight, lpBits, &bi, DIB_RGB_COLORS);

récupérer les pixels en 32 bits/pixel simplifi l'accès :

// tout d'abord on récupère des informations sur la taille du bitmap
BITMAP bmpInfo;
GetObject(hBitmap, sizeof(BITMAP), &bmpInfo);

// allocation mémoire. On va récupérer le bitmap en 32 bits/pixel pour simplifier
// comme cela, on sera sur que chaque ligne du bitmap sera codé sur un nombre
// d'octets multiple de 4. Si le bitmap n'est pas bottom-up (cas le plus fréquent)
// mais top-down, bmpInfo.bmHeight est négatif.
LPBYTE lpBits = new BYTE[4*bmpInfo.bmWidth*bmpInfo.bmHeight];

// initialisation structure BITMAPINFO
BITMAPINFO bi;
memset(&bi, 0, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = bmpInfo.bmWidth;
bi.bmiHeader.biHeight = bmpInfo.bmHeight;
bi.bmiHeader.biBitCount= 32;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biCompression= BI_RGB;

// récupération pixels
HDC hdc = GetDC(NULL);
GetDIBits(hdc, hBitmap, 0, bmpInfo.bmHeight, lpBits, &bi, DIB_RGB_COLORS);
ReleaseDC(NULL, hdc);
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
16 juin 2004 à 11:29
Nickel merci beaucoup !!!
Pour la partie avec getpixel ca deconne toujours, si quelqu'un trouve pourquoi ca m'interesse toujours par curiosité mais comme la seconde methode marche et quelle est 10 fois plus rapide en ce qui me concerne mon probleme est resolu !!!
Et merci aussi pour les modif de code !!!
0