OVH Cloud OVH Cloud

LEcture de pixels de desktop

6 réponses
Avatar
Sivaller
Bonjour,

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

Merci des tuyaux ;

6 réponses

Avatar
Christian ASTOR
Sivaller a écrit :

Je chercherai à lire qu'une seule portion de l'image du desktop



BitBlt()
Avatar
Sivaller
BitBlt()

Je peux avoir un exemple merci ;
Avatar
Arnold McDonald \(AMcD\)
1 - GetWindowDC(GetDesktopWindow())
2 - CreateCompatibleDC()
3 - CreateCompatibleBitmap()
4 - SelectObject(dc,bitmap)
5 - BitBlt()

--
Arnold McDonald (AMcD) - Help #58/2006

http://arnold.mcdonald.free.fr/
Avatar
Christian ASTOR
Sivaller wrote:

BitBlt()

Je peux avoir un exemple merci ;



Je ne vois pas trop le problème...

HBITMAP hBitmap, hBitmapOld;
HDC hDC = GetDC(NULL);
HDC hDCMem = CreateCompatibleDC(hDC);
hBitmap = CreateCompatibleBitmap(hDC, 100, 100);
hBitmapOld = (HBITMAP)SelectObject(hDCMem, hBitmap);
BitBlt(hDCMem, 0, 0, 100, 100, hDC, 0, 0, SRCCOPY);
SelectObject(hDCMem, hBitmapOld);
DeleteDC(hDCMem);
ReleaseDC(NULL, hDC);

hBitmap contiendra une copie du premier carré 100*100 de l'écran.
Avatar
Sivaller
ça marche pas

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
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 ;
Avatar
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(lpbi, BitmapInfoSize, #0);

{Fill in the BitmapInfo structure}
lpbi.bmiHeader.biSize := sizeof(TBitmapInfoHeader);
lpbi.bmiHeader.biWidth := 100;
lpbi.bmiHeader.biHeight := 100;
lpbi.bmiHeader.biPlanes := 1;
lpbi.bmiHeader.biBitCount := 24;
lpbi.bmiHeader.biCompression := BI_RGB;
lpbi.bmiHeader.biSizeImage : ((lpbi.bmiHeader.biWidth *
longint(lpbi.bmiHeader.biBitCount)) div 8) *
lpbi.bmiHeader.biHeight;
lpbi.bmiHeader.biXPelsPerMeter := 0;
lpbi.bmiHeader.biYPelsPerMeter := 0;

lpbi.bmiHeader.biClrUsed := 0;
lpbi.bmiHeader.biClrImportant := 0;

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.