Je cherche à faire un bout de code permettant de lire un bout d'image du
desktop.
Ca ne marche pas getdibits me renvoie 0 ligne copier.
Comment transférer les données du canevas (HDC) au HBITMAP ????
type trgb = record
r,g,b : byte;
end;
var
img : array[0..99,0..99] of TRGB;
var h : hdc;
offscrbmp : hbitmap;
lpbi : BITMAPINFO;
v : integer;
begin
h := getDC(0);
OffscrBmp := CreateCompatibleBitmap(h, 100, 100);
Selectobject(h,offscrbmp);
v := GetDiBits( h, // handle of device context
offscrbmp, // handle of bitmap
0, // first scan line to set in destination bitmap
100, // number of scan lines to copy
@img, // address of array for bitmap bits
lpbi, // address of structure with bitmap data
DIB_RGB_COLORS // RGB or palette index
);
deleteobject(offscrbmp);
releaseDC(0,h);
end;
Ca ne marche pas;
Je chercherai à lire qu'une seule portion de l'image du desktop
fillchar(img,sizeof(img),255); v := GetDiBits( hc, // handle of device context hbitmapold, // handle of bitmap 0, // first scan line to set in destination bitmap 100, // number of scan lines to copy @img, // address of array for bitmap bits lpbi, // address of structure with bitmap data DIB_RGB_COLORS // RGB or palette index ); deleteobject(offscrbmp); DeleteDC(hc); releaseDC(0,h);
fillchar(img,sizeof(img),255);
v := GetDiBits( hc, // handle of device context
hbitmapold, // handle of bitmap
0, // first scan line to set in destination bitmap
100, // number of scan lines to copy
@img, // address of array for bitmap bits
lpbi, // address of structure with bitmap data
DIB_RGB_COLORS // RGB or palette index
);
deleteobject(offscrbmp);
DeleteDC(hc);
releaseDC(0,h);
fillchar(img,sizeof(img),255); v := GetDiBits( hc, // handle of device context hbitmapold, // handle of bitmap 0, // first scan line to set in destination bitmap 100, // number of scan lines to copy @img, // address of array for bitmap bits lpbi, // address of structure with bitmap data DIB_RGB_COLORS // RGB or palette index ); deleteobject(offscrbmp); DeleteDC(hc); releaseDC(0,h);
voilà tout ;
Sivaller
Ca à l'air de marcher avec ceux-ci : procedure TForm1.Button1Click(Sender: TObject); var h,h2,hc : hdc; offscrbmp,hb,hbitmapold : hbitmap; lpbi : BITMAPINFO; v : integer; xf,yf,BitmapInfoSize : word; p4 : pointer; begin h := getDC(0); hc := CreateCompatibleDC(h); hB := CreateCompatibleBitmap(h, 100, 100); hBitmapOld := SelectObject(hc, hb); BitBlt(hc, 0, 0, 100, 100, h, 0, 0, SRCCOPY);
fillchar(img,sizeof(img),255); v := GetDiBits( hc, // handle of device context hb, // handle of bitmap 0, // first scan line to set in destination bitmap 100, // number of scan lines to copy @img, // address of array for bitmap bits lpbi, // address of structure with bitmap data DIB_RGB_COLORS // RGB or palette index ); deleteobject(offscrbmp); DeleteDC(hc); releaseDC(0,h);
end;
et ça à l'air de marcher cette fois.
Ca à l'air de marcher avec ceux-ci :
procedure TForm1.Button1Click(Sender: TObject);
var h,h2,hc : hdc;
offscrbmp,hb,hbitmapold : hbitmap;
lpbi : BITMAPINFO;
v : integer;
xf,yf,BitmapInfoSize : word;
p4 : pointer;
begin
h := getDC(0);
hc := CreateCompatibleDC(h);
hB := CreateCompatibleBitmap(h, 100, 100);
hBitmapOld := SelectObject(hc, hb);
BitBlt(hc, 0, 0, 100, 100, h, 0, 0, SRCCOPY);
fillchar(img,sizeof(img),255);
v := GetDiBits( hc, // handle of device context
hb, // handle of bitmap
0, // first scan line to set in destination bitmap
100, // number of scan lines to copy
@img, // address of array for bitmap bits
lpbi, // address of structure with bitmap data
DIB_RGB_COLORS // RGB or palette index
);
deleteobject(offscrbmp);
DeleteDC(hc);
releaseDC(0,h);
fillchar(img,sizeof(img),255); v := GetDiBits( hc, // handle of device context hb, // handle of bitmap 0, // first scan line to set in destination bitmap 100, // number of scan lines to copy @img, // address of array for bitmap bits lpbi, // address of structure with bitmap data DIB_RGB_COLORS // RGB or palette index ); deleteobject(offscrbmp); DeleteDC(hc); releaseDC(0,h);