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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#define LARGEUR 0
#define HAUTEUR 1
struct imageTab
{
long R;
long G;
long B;
};
int function (char *name,int choix)
{
BITMAPINFOHEADER bmp;
HANDLE file;
DWORD byte;
file = CreateFile(name, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
SetFilePointer(file, 14, 0, FILE_BEGIN);
ReadFile(file, &bmp, sizeof(bmp), &byte, 0);
// bmp contiendra toute l'information nécessaire de ton bitmap
// bmp.biWidth <- largeur
// bmp.biHeight <- hauteur
// bmp.biSizeImage <- Taille total de l'image
// et d'autre. Voir MSDN ici
if(choix==0)
{
return bmp.biWidth;
}
else if(choix==1)
{
return bmp.biHeight;
}
CloseHandle(file);
}
//dans le main:
HINSTANCE hInst;
HBITMAP hBmp;
hBmp =BITMAPLoad(hInst,"monBitmap.bmp", FALSE, TRUE);//ouverture de l'image
int imgLargeur=function("monBitmap.bmp",LARGEUR);
int imgHauteur=function("monBitmap.bmp",HAUTEUR);
HDC hdc = CreateCompatibleDC(NULL);
HGDIOBJ hOldBmp = SelectObject(hdc, hBmp);
/*##########création d'un tableau dynamique à deux dimensions de type imageTab #########
imageTab **image=new imageTab*[imgLargeur];
for (int i=0;i<imgLargeur;i++)
{
image[i]=new imageTab [imgHauteur];
}
##################################################################*/
COLORREF pix;
/*#####################remplissage du tableau ##############################
for(int x=0;x<imgLargeur;x++)
{
for(int y=0;y<imgHauteur;y++)
{
pix = GetPixel(hdc, x, y);
image[x][y].R=GetRValue(pix);
image[x][y].G=GetGValue(pix);
image[x][y].B=GetBValue(pix);
}
}
##################################################################*/
COLORREF pix;
/*******************************programme**********************************/
//ne surtout pas oublier de détruire le hdc et le tableau dynamique
SelectObject(hdc, hOldBmp);
DeleteDC(hdc);
for ( int i=0 ; i < imgLargeur ; i++)
{
delete image [i];
}
delete image; |