PDA

View Full Version : گرفتن عکس به طور دلخواه از صفحه ی نمایش



dkhatibi
چهارشنبه 03 خرداد 1385, 19:26 عصر
می خواهم از صفحه ی نمایش و به طور دلخواه و با اندازه های دلخواه عکس بگیرم
چه راهی را پیشنهاد می کنید؟

freebird
جمعه 05 خرداد 1385, 13:51 عصر
procedure TForm1.Button1Click(Sender: TObject);
var
dc: HDC; lpPal : PLOGPALETTE;
Width,Height,x,y : integer;
bm : TBitMap;
begin
{test width and height}
Width:=100;
Height:=100;
x:=0;
y:=0;
bm := TBitmap.Create;
if ((Width = 0) OR (Height = 0)) then exit;
bm.Width := Width;
bm.Height := Height;
{get the screen dc}
dc := GetDc(0);
if (dc = 0) then exit;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) AND RC_PALETTE = RC_PALETTE) then
begin
{allocate memory for a logical palette}
GetMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));
{zero it out to be neat}
FillChar(lpPal^, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)), #0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries :=GetSystemPaletteEntries(dc,0,256,lpPal^.palPalEn try);
if (lpPal^.PalNumEntries <> 0) then
begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, sizeof(TLOGPALETTE) + (255 * sizeof(TPALETTEENTRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,0,0,Width,Height,Dc,x,y,SR CCOPY);
Image1.Picture.Bitmap := bm;
{release the screen dc}
ReleaseDc(0, dc);
end;

X,y نقطه شروع هست و width و height هم که طول و عرض تصویری که می خواهید از desktop بگیرید مشخص می کند. در ضمن این کد رو از توی سورس یک برنامه ای copy و paste کردم.