Page 1 of 1

invalid meta file created by RichViewEdit1.RVData.PaintTo( )

Posted: Mon Sep 13, 2010 7:25 pm
by MikeP
the rvf file is simple...it only contains two words.

the resulting .wmf file is corrupt. the resulting .bmp file is good.

i'm surprised there are no attachments supported here; i'd include the sample app.

how can i fix this?

thank you!
mp

procedure TForm1.btnRenderToPictureClick(Sender: TObject);
const
VERYLARGEVALUE = $FFFFFFF;
var
iWidth, iHeight:integer;
mfCanvas: TMetafileCanvas;
bmp:TBitmap;
wmf : TMetafile;
begin
RichViewEdit1.LoadRVF('r.rvf');
RichViewEdit1.Format;
RichViewEdit1.Reformat;

RichViewEdit1.HScrollPos := 0;
RichViewEdit1.VScrollPos := 0;
RichViewEdit1.Deselect;
RichViewEdit1.Invalidate;

iWidth := RichViewEdit1.RVData.DocumentWidth + RichViewEdit1.LeftMargin + RichViewEdit1.RightMargin;
iHeight := RichViewEdit1.RVData.DocumentHeight;

// surely these are not needed
// RichViewEdit1.Width:=iWidth;
// RichViewEdit1.Height:=iHeight;

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

mfCanvas := TMetafileCanvas.Create(wmf, 0);
mfCanvas.Brush.Color := clRed;// clWhite;
mfCanvas.FillRect(Rect(0, 0, iWidth, iHeight));

RichViewEdit1.RVData.PaintTo(mfCanvas, Rect(0, 0, VERYLARGEVALUE, VERYLARGEVALUE),
False, False, False, False, 0, 0);

// file is corrupt
wmf.SaveToFile('r.wmf');
mfCanvas.Free;
wmf.Free;





bmp:=TBitmap.Create;
bmp.Width := iWidth;
bmp.Height := iHeight;
bmp.Canvas.Brush.Color := clRed;// clWhite;
bmp.Canvas.FillRect(Rect(0, 0, iWidth, iHeight));

RichViewEdit1.RVData.PaintTo(bmp.Canvas,
Rect(0, 0, VERYLARGEVALUE, VERYLARGEVALUE),
False,
False,
False,
False,
0,
0);

// file is ok
bmp.SaveToFile('r.bmp');
bmp.Free;
end;

Posted: Tue Sep 14, 2010 11:39 am
by Sergey Tkachenko
Free mfCanvas BEFORE saving to a file.

Posted: Tue Sep 14, 2010 3:20 pm
by MikeP
Sergey Tkachenko wrote:Free mfCanvas BEFORE saving to a file.
i learned something new...thank you!