读书人

如何将RichViewEdit打印成一张张bmp图

发布时间: 2013-07-09 09:50:48 作者: rapoo

怎么将RichViewEdit打印成一张张bmp图片(bmp长宽要自定义)
看了这个,但不知道在cb中要怎么用.谁能帮忙改一下,比如我要一页页打印成200*50这么大的bmp.

http://blog.csdn.net/qq752923276/article/details/7869711



1:var wmf: TMetafile;
Canvas: TMetafileCanvas;
Width, Height: Integer;
begin
RVReportHelper1.Init(Self.Canvas, 200 {width});
while RVReportHelper1.FormatNextPage(VERYLARGEVALUE) do;

wmf := TMetafile.Create;
wmf.Width := 200;
wmf.Height := RVReportHelper1.EndAt;

Canvas := TMetafileCanvas.Create(wmf, 0);
RVReportHelper1.DrawPage(1,Canvas,True,RVReportHelper1.EndAt);
Canvas.Free;

Image2.Picture.Graphic := wmf;
wmf.Free;
end;
2:var wmf: TMetafile;
Canvas: TMetafileCanvas;
Width, Height: Integer;
begin
RichView1.HScrollPos := 0;
RichView1.VScrollPos := 0;
RichView1.Deselect;
RichView1.Invalidate;
Width := RichView1.RVData.DocumentWidth RichView1.LeftMargin RichView1.RightMargin;
Height := RichView1.RVData.DocumentHeight;

wmf := TMetafile.Create;
wmf.Width := Width;
wmf.Height := Height;

Canvas := TMetafileCanvas.Create(wmf, 0);
Canvas.Brush.Color := clWindow;
Canvas.FillRect(Rect(0,0,Width,Height));
RichView1.RVData.PaintTo(Canvas, Rect(0,0,VERYLARGEVALUE,VERYLARGEVALUE));
Canvas.Free;

Image1.Picture.Graphic := wmf;
wmf.Free;
end;


[解决办法]
翻译后大概是这个样子:
RVReportHelper1->Init(Canvas, 200);  
while (RVReportHelper1->FormatNextPage(VERYLARGEVALUE));

TMetafile *wmf = new TMetafile();
wmf->Width = 200;
wmf->Height = RVReportHelper1->EndAt;

TMetafileCanvas *pCanvas = new TMetafileCanvas(wmf, 0);
RVReportHelper1->DrawPage(1, pCanvas, true, RVReportHelper1->EndAt);
delete pCanvas;

Image2->Picture->Graphic = wmf;
delete wmf;
RichView1->HScrollPos = 0;  
RichView1->VScrollPos = 0;
RichView1->Deselect();
RichView1->Invalidate();
int nWidth = RichView1->RVData->DocumentWidth - RichView1->LeftMargin - RichView1->RightMargin;
int nHeight = RichView1->RVData->DocumentHeight;


TMetafile *wmf = new TMetafile();
wmf->Width = nWidth;
wmf->Height = nHeight;

TMetafileCanvas *pCanvas = new TMetafileCanvas(wmf, 0);
pCanvas->Brush->Color = clWindow;
pCanvas->FillRect(Rect(0, 0, nWidth, nHeight));
RichView1->RVData->PaintTo(pCanvas, Rect(0, 0, VERYLARGEVALUE, VERYLARGEVALUE));
delete pCanvas;

Image1->Picture->Graphic = wmf;
delete wmf;


[解决办法]
Init函数中的Canvas参数,在Delphi代码中是Self.Canvas,相当于C++Builder中的this->Canvas,默认应该是窗体类的Canvas对象。

至于VERYLARGEVALUE,你需要在原来的Delphi代码中查找其真实的值,然后define或const定义一下就行了。
[解决办法]
http://download.csdn.net/detail/qq752923276/5322562
RichView文本内容转Bmp

读书人网 >C++ Builder

热点推荐