怎样将canvas上面的图形输出保存为BMP文件,并且打印出来?

beerboy 2004-04-25 09:40:44
我开发了一个程序,在PaintBox上面的Canvas上面画图,我想将图形保存下来,并且提供打印功能。由于图形很大,屏幕显示不下,我靠滚动条来拖动才能看到整个图形,我保存时候如下:
TRect Rect;
Rect.Left=0;
Rect.Top=0;
Rect.Right=PBox->Width;
Rect.Bottom=PBox->Height;
Graphics::TBitmap *bmp=new Graphics::TBitmap();
bmp->Width=Rect.Right;
bmp->Height=Rect.Bottom;
bmp->Canvas->CopyRect(Rect,PBox->Canvas,Rect);
if(SaveDialog->Execute())
{
bmp->SaveToFile(SaveDialog->FileName);
}
但保存的结果却是当前屏幕显示内容,其他没有显示的部分就打印不出来了。降上面的Rect边界更改也不行。
另外,怎么打印我整个Canvas上面的图形呢?
希望高手解答。
...全文
496 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
JetKingLau 2004-04-29
  • 打赏
  • 举报
回复
Graphics::TBitmap *bmp = new Graphics::TBitmap();//新建一个内存位图
bmp->Width = Screen->Width;//设置位图大小
bmp->Height = Screen->Height;
bmp->Canvas->Brush->Color = clWhite;//设置位图背景画刷
bmp->Canvas->Brush->Style = bsSolid;
bmp->Canvas->FillRect(bmp->Canvas->ClipRect);//背景填充

//画图
bmp->Canvas->MoveTo(0,0);
bmp->Canvas->LineTo(bmp->Width,bmp->Height);

//居中显示文本
AnsiString str = "测试文本";
bmp->Canvas->TextOut(
bmp->Width/2 - bmp->Canvas->TextWidth(str)/2,
bmp->Height/2 - bmp->Canvas->TextHeight(str)/2,
str);

bmp->SaveToFile("abc.bmp");//保存
delete bmp;//释放
beerboy 2004-04-29
  • 打赏
  • 举报
回复
试试吧,不过,哪位能给出一个在内存画图,然后保存下来的MODEL么?先谢谢。
lihongxing2002 2004-04-28
  • 打赏
  • 举报
回复
再顶
zhenghaiou 2004-04-26
  • 打赏
  • 举报
回复
我同意大家的看法先用TBitmap作图,再拷贝到PaintBox。
不过在BCB中的TImage组件可以按照您的思路完成您的需求。试试吧。
JetKingLau 2004-04-26
  • 打赏
  • 举报
回复
在 PaintBox 上面的 Canvas 画图,不可见的区域是不会处理的,(楼上的 GetFormImage() 与不能获得屏幕之外的图片信息)。

一般都是在内存位图中画,需要显示、输出时才将内存位图的 Canvas 复制(CopyRect或API BitBlt等函数)到目标 Canvas 中。
zxcdewq 2004-04-26
  • 打赏
  • 举报
回复
Graphics::TBitmap *bmp=new Graphics::TBitmap();
bmp->Width=Rect.Right;
bmp->Height=Rect.Bottom;

bmp->Canvase

你可以这样现在内存画图,在拷贝到PaintBox上面,这样不但可以保存完整图片,还可以防止闪烁
lihongxing2002 2004-04-26
  • 打赏
  • 举报
回复
kerbcurb 2004-04-26
  • 打赏
  • 举报
回复
可以使用GetFormImage()

This example uses an image, a button, and a shape component on a form. When the user clicks the button, an image of the form is stored in the FormImage variable and copied to the Clipboard. Then image of the form in then copied back to the image component, producing an interesting result, especially if the button is clicked multiple times.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics::TBitmap *FormImage = GetFormImage();
try
{
Clipboard()->Assign(FormImage);
Image1->Picture->Assign(Clipboard());
}
__finally
{
delete FormImage;
}
}
//------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Shape1->Shape = stEllipse;
Shape1->Brush->Color = clLime;

Image1->Stretch = true;
}

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧