请问如何把TPaintBox上的图片保存为BMP或者JPG文件? 如题~~~~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function GetClipBitmapFromDC(DC: HDC; x, y, Width, Height: Integer): HBITMAP;var memDC: HDC; oldBmp: HBITMAP;begin Result := CreateCompatibleBitmap(DC, Width, Height); memDC := CreateCompatibleDC(DC); oldBmp := SelectObject(memDC, Result); try BitBlt(memDC, 0, 0, Width, Height, DC, x, y, SRCCOPY); finally SelectObject(memDC, oldBmp); DeleteDC(memDC); end;end;// TPaintBox.Canvas.Handle只有在Paint事件中才是有效的,所以可设置某个外部条件,满足时保存图像procedure TForm1.PaintBox1Paint(Sender: TObject);var bmp: TBitmap;begin .... // 画图代码略 if 条件 then begin bmp := TBitmap.Create; // x,y,Width,Height是给定矩形尺寸 bmp.Handle := GetClipBitmapFromDC(PaintBox1.Canvas.Handle, 0, 0, PaintBox1.Width, PaintBox1.Height); bmp.SaveToFile('1.bmp'); bmp.Free; end;end; procedure TForm1.Button1Click(Sender: TObject);var bmp: TBitmap;begin bmp := TBitmap.Create; bmp.Width := PaintBox1.Width; bmp.Height := PaintBox1.Height; bmp.PixelFormat := pf24Bit; bmp.Canvas.CopyRect(Rect(0, 0, bmp.Width, bmp.Height), PaintBox1.Canvas, Rect(0, 0, bmp.Width, bmp.Height)); bmp.SaveToFile('c:\temp.bmp'); bmp.Free;end; 重新问.自动登陆并且获取用户信息; service /install 这个安装时怎么才能不提示呢?? 都有什么Delphi写的关系数据库 关于如何使DELPHI窗口永远成为当前窗口!!!急急急!!! 几个简单SQL语句问题,欢迎进来看看。 一個關於speedbutton的問題 两个表的连接,急急急急,本人拿出全部财产,求助,快快快快 承诺大送分!!Delphi的通讯端口控件有哪些,对于串口IC卡读写器的控制问题,再线等候,谢谢!!! 想在一个程序中,按下F1能显示帮助文件要如何设置? 有个很简单的问题,请教高手! 限制图片尺寸的时候遇到的问题 一个内存读取语句的写法
Height: Integer): HBITMAP;
var
memDC: HDC;
oldBmp: HBITMAP;
begin
Result := CreateCompatibleBitmap(DC, Width, Height);
memDC := CreateCompatibleDC(DC);
oldBmp := SelectObject(memDC, Result);
try
BitBlt(memDC, 0, 0, Width, Height, DC, x, y, SRCCOPY);
finally
SelectObject(memDC, oldBmp);
DeleteDC(memDC);
end;
end;// TPaintBox.Canvas.Handle只有在Paint事件中才是有效的,所以可设置某个外部条件,满足时保存图像
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
bmp: TBitmap;
begin
.... // 画图代码略
if 条件 then
begin
bmp := TBitmap.Create;
// x,y,Width,Height是给定矩形尺寸
bmp.Handle := GetClipBitmapFromDC(PaintBox1.Canvas.Handle,
0, 0, PaintBox1.Width, PaintBox1.Height);
bmp.SaveToFile('1.bmp');
bmp.Free;
end;
end;
var
bmp: TBitmap;
begin
bmp := TBitmap.Create;
bmp.Width := PaintBox1.Width;
bmp.Height := PaintBox1.Height;
bmp.PixelFormat := pf24Bit;
bmp.Canvas.CopyRect(Rect(0, 0, bmp.Width, bmp.Height), PaintBox1.Canvas, Rect(0, 0, bmp.Width, bmp.Height));
bmp.SaveToFile('c:\temp.bmp');
bmp.Free;
end;