Silly question, I'm sure. When I make the following call, The image drops nicely into the editor.
var
img: TImage;
begin
if not dlgOpenPicture.Execute then
Exit;
img := TImage.Create(nil);
img.Picture.LoadFromFile(dlgOpenPicture.FileName);
rvEdit.InsertPicture('', img.Picture.Graphic, rvvaBaseLine);
end;
However, if I call rvEdit.BackgroundBitmap := img.Picture.Bitmap; instead of InsertPicture, the background just stays white.
Can someone tell me how I can add a background image please?
Many thanks in advance.
Stuart
Background Image
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
1. Your code has a memory leak. TRichView will free img.Picture.Graphic, but img itself will not be freed.
Use this code:
Use this code:
Code: Select all
var
img: TImage;
gr: TGraphic;
begin
if not dlgOpenPicture.Execute then
Exit;
img := TImage.Create(nil);
try
img.Picture.LoadFromFile(dlgOpenPicture.FileName);
gr := RV_CreateGraphics(TGraphicClass(img.Picture.Graphic.ClassType)); // defined in RVFuncs.pas
gr.Assign(img.Picture.Graphic)
rvEdit.InsertPicture('', gr, rvvaBaseLine);
finally
img.Free;
end;
end;
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
2. Assign BackgroundStyle property. By default it is bsNoBitmap, meaning no picture. Other property values specifies position, stretching and tiling for the background image.
PS: You can create and use TPicture object instead of TImage.
Code: Select all
var
img: TImage;
begin
if not dlgOpenPicture.Execute then
Exit;
img := TImage.Create(nil);
try
img.Picture.LoadFromFile(dlgOpenPicture.FileName);
rvEdit.BackgroundBitmap := img.Picture.Bitmap; // convert picture to bitmap and copy it
rvEdit.BackgroundStyle := bcCentered;
finally
img.Free;
end;
end;