怎样把paintbox中绘制的图形保存到image或canvas或bmp(100分)

  • 主题发起人 主题发起人 edoxs
  • 开始时间 开始时间
E

edoxs

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样把paintbox中绘制的图形保存到或canvas或bmp,并且paintbox 大于一个屏幕的,
 
可以这样:
把PaintBox1中指定区域的图像拷贝到image1的指定区域。如果是完整拷贝,你事情全部宽度和高度就好。
var MyRect,MyOther:TRect;
Image1.Canvas.CopyRect(MyOther,PaintBox1.Canvas,MyRect);
 
procdure TForm1.Button1Click(Sender: TObject);
var
Bmp: TBitMap;
begin
Bmp := TBitMap.Create;
Bmp.Width := PaintBox1.Width;
Bmp.Height:= PaintBox1.Height;
with Bmp.Canvas do
begin
CopyRect(PaintBox1.Canvas);
end;
Bmp.SaveToFile('./1.bmp');
FreeAndNil(Bmp);
end;
 
各位,我用上面的方法试了,但是当只能把屏幕拷贝下来啦,在屏幕外的部分就是空白的,还希望多多指教!!!!
 
var
Bitmap: TBitmap;
ARect: TRect;
FilePath: string;
begin
try
ARect := PaintBox1.ClientRect;

Bitmap := TBitmap.Create;
Bitmap.Width := ARect.Right;
Bitmap.Height := ARect.Bottom;
Bitmap.Canvas.CopyRect(ARect, PaintBox1.Canvas, ARect);

dlgSave.FileName := 'xx.bmp';
if dlgSave.Execute then
begin
FilePath := dlgSave.FileName;
if UpperCase(ExtractFileExt(FilePath)) <> UpperCase('.bmp') then
FilePath := FilePath + '.bmp';
Bitmap.SaveToFile(FilePath);
end;
finally
FreeAndNil(Bitmap);
end;
 
问题: 重金求解:怎样把paintbox中绘制的图形保存到image或canvas或bmp,然后打印出来! ( 积分: 300 )
分类: 图形图象

来自: ydiandian, 时间: 2001-11-07 19:39:00, ID: 714271
我在paintbox中利用他的canvas属性来绘制需要的图形,然后要将绘制
好的图形打印出来,怎样才能将需要的部分打印出来呢?
急!谢谢

来自: ydiandian, 时间: 2001-11-07 19:43:00, ID: 714281
原来是 copy,
具体怎么用呢?

来自: BornKilled, 时间: 2001-11-07 19:44:00, ID: 714283
如果要打印的效果好的话,还是直接在printer 的canvas上画比较合适
你为什么不同时画两份?

来自: 卷起千堆雪tyn, 时间: 2001-11-07 19:46:00, ID: 714286
你首先将PaintBox绘制的图形这样处理 :
var
bmp :TBitmap;
begin
bmp :=TBitmap.Create;
bmp.Width :=PaintBox.Width;
bmp.Height :=PaintBox.Height;
BitBlt(bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,PaintBox.Canvas.Handle,0,0,SRCCOPY);
Image.AutoSize :=True;
Image.Picture.Bitmap.Assign(bmp);
bmp.Free;
end;

打印:
var
ScaleX,ScaleY :Integer;
R :TRect;
begin
if Printer.Printers.Count=0 then
begin
ShowMessage('请首先安装打印机');
Exit; //跳出N11Click
end;
if not PrintDialog.Execute then Exit
else
begin
with Printer do
begin
BeginDoc;
ScaleX :=GetDeviceCaps(Handle,LogPixelsX) div PixelsPerInch;
ScaleY :=GetDeviceCaps(Handle,LogPixelsY) div PixelsPerInch;
R :=Rect(0,0,Image.Width*ScaleX,Image.Height*ScaleY);
Canvas.StretchDraw(R,Image.Picture.Graphic);
EndDoc;
end;
end;
end;

来自: ydiandian, 时间: 2001-11-07 19:55:00, ID: 714293
卷起千堆雪tyn:马上看看行否?
BornKilled:下次试一下你的方法!
先谢了

来自: ydiandian, 时间: 2001-11-07 20:15:00, ID: 714339
图形打印出来了,但背景色不是白色.
打印出来的东西,背景色怎么设置为白色呢?

来自: ydiandian, 时间: 2001-11-07 20:36:00, ID: 714408
对了,还有,怎样将图形放大打印出来呢?

来自: ydiandian, 时间: 2001-11-08 13:25:00, ID: 715876
BornKilled:直接在printer 的canvas上画比较合适,但是怎么画呢?
画完的图形怎么打印出来呢?

来自: 卷起千堆雪tyn, 时间: 2001-11-08 13:32:00, ID: 715899
你打印出来的背景色是什么?


R :=Rect(0,0,Image.Width*ScaleX,Image.Height*ScaleY);
这是按照原图大小打印 , 你如果想放大打印, 可以改变这两个值:

Image.Width*ScaleX和Image.Height*ScaleY,比如都乘以某个系数,可以分别是不同的系数.

来自: ydiandian, 时间: 2001-12-10 20:00:00, ID: 777882
谢谢

来自: ydiandian, 时间: 2001-12-11 9:32:00, ID: 778764
xie xie

来自: ydiandian, 时间: 2001-12-11 9:38:00, ID: 778795
谢谢

得分大富翁: BornKilled-80,卷起千堆雪tyn-220,
 
各位大大,我的PaintBox中的图象只有一部分是显示在机器屏幕上,另外一部分在屏幕之外,各位给出的方法,好象都只能保证屏幕之中的部分能够被保持到文件中,其他就不行了
 
而且这样做还有一个问题,好象是在进行屏幕拷贝一样,如果我把应用的主窗口大小调整了一下,那得到的图片的结果就又不一样啦!!!![:)]
 
后退
顶部