将图片保存为bmp格式的,图片有点大;
代码如下:
var dc:HDC; fullCanvas:TCanvas; bm:TBitmap; dlg1: TSavePictureDialog;begin dc:=GetDC(0); fullCanvas:=TCanvas.Create; dlg1:=TSavePictureDialog.Create(nil); bm:=TBitmap.Create; fullCanvas.Handle:=dc; try if dlg1.Execute then begin bm.Width:=Screen.Width; bm.Height:=Screen.Height; bm.Canvas.CopyRect(Rect(0,0,bm.Width,bm.Height),fullCanvas,Rect(0,0,Screen.Width,Screen.Height)); bm.SaveToFile(dlg1.FileName+'.bmp'); end; finally fullCanvas.Free; dlg1.Free; bm.Free; end;end;
将图片保存为png格式的,这时候的图片就小了很多。
var pg:TPngObject; dc:HDC; fullCanvas:TCanvas; bm:TBitmap; dlg1: TSavePictureDialog;begin dc:=GetDC(0); fullCanvas:=TCanvas.Create; bm:=TBitmap.Create; dlg1:=TSavePictureDialog.Create(nil); pg:=TPngObject.Create; fullCanvas.Handle:=dc; try if dlg1.Execute then begin bm.Width:=Screen.Width; bm.Height:=Screen.Height; bm.Canvas.CopyRect(Rect(0,0,bm.Width,bm.Height),fullCanvas,Rect(0,0,Screen.Width,Screen.Height)); pg.Assign(bm); pg.SaveToFile(dlg1.FileName+'.png'); end; finally fullCanvas.Free; bm.Free; dlg1.Free; pg.Free; end;end;
参考:http://www.cnblogs.com/zhwx/archive/2012/05/16/2503524.html
联系客服