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
|
unsigned int i = 0;
unsigned int j = 0;
unsigned int k = 0;
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biClrImportant = 0;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biHeight = ht;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biWidth = wh;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
HDC hdc=::GetDC(m_hWnd);
unsigned char *bits=(unsigned char *) malloc ( ((long int) (( bmi.bmiHeader.biWidth*3 + bmi.bmiHeader.biWidth%4 ) * bmi.bmiHeader.biHeight )) * sizeof(unsigned char));
long int cnt=0;
for(i=0;i<bmi.bmiHeader.biHeight;i++)
{
for(j=0;j<bmi.bmiHeader.biWidth;j++)
{
couleur = GetPixels(hdc,j,i);
int r = (couleur>>16)&0x000000ff;
int v = (couleur>>8)&0x000000ff;
int b = couleur & 0x000000ff;
//conversion en niveau de gris
int lum = (int)(.299 * (double)(r) + .587 * (double)(v) + .114 * (double)(b));
bits[cnt+2] = lum;
bits[cnt+1] = lum;
bits[cnt] = lum;
cnt+=3;
}
//Chaque ligne doit etre multiple de 4
for (j=0;j<bmi.bmiHeader.biWidth%4;j++)
{
bits[cnt] = 0;
cnt++;
}
}
SetDIBitsToDevice(hdc,0,0,(DWORD)wh,(DWORD)ht,0,0,0,
(WORD)ht,bits,(LPBITMAPINFO)&bmi,DIB_RGB_COLORS); |
Partager