Delphi 7,如何将Paintbox内容复制到Tbitmap?
我正在使用 delphi 7,我想如何将 TpaintBox 的内容复制/分配给 Tbitmap?
像这样
public
{ Public declarations }
BitMap : TBitmap;
end;
我有一个Tbitmap声明为公共,我像这样在FormCreate上创建它
procedure TForm1.FormCreate(Sender: TObject);
begin
BitMap := TBitMap.Create;
end;
然后我
procedure TForm1.DrawOnPainBox;
begin
If BitMap.Width <> PaintBox1.Width then BitMap.Width := PaintBox1.Width;
If BitMap.Height <> PaintBox1.Height then BitMap.Height := PaintBox1.Height;
BitMap.Canvas.Rectangle(0,0,random(PaintBox1.Width ),random(PaintBox1.Height));
PaintBox1.Canvas.Draw(0,0,BitMap);
end;
用PaintBox1.Canvas.Draw(0,0,BitMap);在位图上绘制一些东西,我们可以显示什么位图中有油漆盒,但相反的方式是什么?
如何将绘画盒的内容分配/复制到位图?
`BitMap:=PaintBox1.Canvas.Brush.Bitmap;`
这个编译,但如果我这样做并再次调用过程TForm1.DrawOnPainBox;
我得到访问冲突
并且调试器显示位图
和PaintBox1.Canvas.Brush.Bitmap
即使在paintBox上绘制了一些线条
im working on delphi 7 and i want to how to copy/assign the content of a TpaintBox to a Tbitmap?
like this
public
{ Public declarations }
BitMap : TBitmap;
end;
i have a Tbitmap declared as public and i create it onFormCreate like this
procedure TForm1.FormCreate(Sender: TObject);
begin
BitMap := TBitMap.Create;
end;
Then i draw somthing on the bitmap like this
procedure TForm1.DrawOnPainBox;
begin
If BitMap.Width <> PaintBox1.Width then BitMap.Width := PaintBox1.Width;
If BitMap.Height <> PaintBox1.Height then BitMap.Height := PaintBox1.Height;
BitMap.Canvas.Rectangle(0,0,random(PaintBox1.Width ),random(PaintBox1.Height));
PaintBox1.Canvas.Draw(0,0,BitMap);
end;
with PaintBox1.Canvas.Draw(0,0,BitMap);
we can display what is there in Bitmap to a paintbox but what is the reverse way?
how to assign/copy content of a paintbox to a bitmap?
`BitMap:=PaintBox1.Canvas.Brush.Bitmap;`
this compiles but if i do this and again call the procedure TForm1.DrawOnPainBox;
i get access Violation
and the debugger show the bitmap
and PaintBox1.Canvas.Brush.Bitmap
even though some lines are drawn on the paintBox
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将
TPaintBox
(我们称之为PaintBox1
)的内容分配给TBitmap
(例如Bitmap
), 注意:在较新版本的 Delphi 中,您可以使用
Bitmap.SetSize
代替Bitmap.Width
和Bitmap.Height
。To assign the contents of a
TPaintBox
(let's call itPaintBox1
) to aTBitmap
(Bitmap
, say), you can doNotice: In newer versions of Delphi, you can use
Bitmap.SetSize
instead ofBitmap.Width
andBitmap.Height
.TBitmap.setsize 已在 Delphi 2006 中引入,您可能使用的是旧版本。只需更换
Bitmap.SetSize (X, Y)
它的速度
您将编译代码
较慢(但只有在循环中使用它时才重要),但如果这种情况发生得太频繁, ,声明一个新的单位 BitmapSize。 pas:
然后用 TBitmapSize 替换位图 TBitmap 的声明和创建。
TBitmap.setsize has been introduced in Delphi 2006, you may be using an older version. Just replace
Bitmap.SetSize (X, Y)
by
it's slower (but it matters only if you use it in a loop), but you will compile the code
if this happens too often, declare a new unit BitmapSize.pas:
then replace in declaration and creation of your bitmap TBitmap with TBitmapSize.