Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

星期五, 9月 07, 2007

擷取畫面並存成BMP及JPG檔案


uses Windows, Graphics, Jpeg;

procedure TForm1.Button1Click(Sender: TObject);
var
dc:hdc;
MyCanvas:TCanVas;
Bmp:TBitmap;
Jpg: TJpegImage;
begin
application.Minimize; //視窗最小化
application.ProcessMessages; //視窗取得控制
//可能要delay一下,不然抓到空白東東
Jpg := TJpegImage.Create;
MyCanvas:=TCanvas.Create;
Bmp:=tbitmap.Create;
dc:=getdc(0);
try
MyCanvas.Handle := DC;

Bmp.Width := Width;
Bmp.Height := Height;
Bmp.Canvas.CopyRect(Rect(0,0,Screen.Width,Screen.Height),MyCanvas,Rect (0,0,Screen.Width,Screen.Height));
Image1.Picture.Bitmap.Assign(Bmp);
Bmp.SaveToFile('test.Bmp');

Jpg.Assign(Bmp);
Jpg.Performance:=jpBestQuality;
Jpg.CompressionQuality := 30; //你想要的壓縮品質
Jpg.Compress;
Jpg.SaveToFile('test.jpg');
finally
releasedc(0,dc);
MyCanvas.Free;
Bmp.Free;
end;
application.Restore; //視窗回復
end;

沒有留言: