how to put background image at runtime?
how to put background image at runtime?
Sergey Hello, I would like to know how to put an image in the background of the text at run time.
thanks
thanks
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
To define a background picture, assign BackgroundBitmap and BackgroundStyle properties.
As for pictures on pages, there are two solutions.
1) This feature requires the newest beta version.
Insert a textbox in a header (or in a footer), insert a picture in this textbox.
Insert another picture in a header (or a footer) for even pages.
Assign RVPrint.FacingPages (or SRichViewEdit.PageProperty.FacingPages) = True.
2) Use RVPrint.OnPagePrepaint (or SRichViewEdit.OnPaintPage) event to draw pictures yourself.
There is a demo, http://www.trichview.com/support/files/crocoprint.zip , it's quite old, but I hope it still works.
As for pictures on pages, there are two solutions.
1) This feature requires the newest beta version.
Insert a textbox in a header (or in a footer), insert a picture in this textbox.
Insert another picture in a header (or a footer) for even pages.
Assign RVPrint.FacingPages (or SRichViewEdit.PageProperty.FacingPages) = True.
2) Use RVPrint.OnPagePrepaint (or SRichViewEdit.OnPaintPage) event to draw pictures yourself.
There is a demo, http://www.trichview.com/support/files/crocoprint.zip , it's quite old, but I hope it still works.
I'm doing the following:
but nothing happens, what do I doing wrong?
Code: Select all
procedure TFrmCadEditorMinutasTab.FormCreate(Sender: TObject);
procedure GetPrinterPixelsPerInch;
var DC: Cardinal;
begin
DC := RV_GetPrinterDC;
PrinterHPixelsPerInch := GetDeviceCaps(DC,LOGPIXELSX);
PrinterVPixelsPerInch := GetDeviceCaps(DC,LOGPIXELSY);
DeleteDC(DC);
end;
begin
Imagem := TImage.Create(nil);
Imagem.Picture.LoadFromFile('C:\compartilhado\Imagens\adsf22.jpg');
GetPrinterPixelsPerInch;
Image1Width := Round(Imagem.Picture.Graphic.Width * PrinterHPixelsPerInch / Screen.PixelsPerInch);
Image1Height := Round(Imagem.Picture.Graphic.Height * PrinterHPixelsPerInch / Screen.PixelsPerInch);
Image2Width := Round(Imagem.Picture.Graphic.Width * PrinterHPixelsPerInch / Screen.PixelsPerInch);
Image2Height := Round(Imagem.Picture.Graphic.Height * PrinterHPixelsPerInch / Screen.PixelsPerInch);
end;
procedure TFrmCadEditorMinutasTab.PrintImage(Canvas: TCanvas; X,Y: Integer; gr: TGraphic;
ToScreen: Boolean);
var bmp: TBitmap;
begin
// RV_PictureToDevice understands only bitmaps
bmp := TBitmap.Create;
bmp.Assign(gr);
RV_PictureToDevice(Canvas,X,Y,gr.Width,gr.Height,@(TCustomMainPtblRVData(SRichViewEdit1.RichViewEdit.RVData).PrnSad),bmp,ToScreen,RVStyle1.GraphicInterface);
bmp.Free;
end;
procedure TFrmCadEditorMinutasTab.SRichViewEdit1PaintPage(Sender: TObject;
PageNo: Integer; PageRect,R: TRect; Canvas: TCanvas; Prepaint,
Printing: Boolean);
begin
inherited;
if PageNo mod 2 <> 0 then
begin
PrintImage(Canvas,(PageRect.Left + PageRect.Right - Image2Width) div 2,(PageRect.Top + PageRect.Bottom - Image2Height) div 2,Imagem.Picture.Graphic,true)
else
PrintImage(Canvas,(PageRect.Left + PageRect.Right - Image2Width) div 2,(PageRect.Top + PageRect.Bottom - Image2Height) div 2,Imagem.Picture.Graphic,true);
end;
used this in SRichViewEdit1PaintPage, this is what I want, but with the image behind the text:
with RV_PictureToDevice nothing happens:
Code: Select all
RV_PictureToDeviceAlt(Canvas,(PageRect.Left + PageRect.Right - PIC.Height) div 2,(PageRect.Top + PageRect.Bottom - PIC.Width) div 2,PIC.Width,PIC.Height,PIC.Bitmap);
Code: Select all
RV_PictureToDevice(Canvas,(PageRect.Left + PageRect.Right - PIC.Height) div 2,(PageRect.Top + PageRect.Bottom - PIC.Width) div 2,PIC.Width,PIC.Height,@(TPrintableRVData(SRichViewEdit1.RichViewEdit.RVData).PrnSad),PIC.Bitmap,true,RVStyle1.GraphicInterface);
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
For ScaleRichView, it's even simpler than for TRVPrint.
This code displays a bitmap from Image1 on even pages of SRichViewEdit1, at the top left corner of the main text area.
The picture is scaled by 0.5 (see Scale constant)
You tried adapting a code for TRVPrint, and not all was made correct.
Typecasting to TCustomMainPtblRVData is wrong, this kind on RVData exists only in TRVPrint and TRVReportHelper. ScaleRichView does not use a printer resolution explicitly, so "sad" object can be nil.
As for GraphicInterface object, and object from any RVStyle can be used, they are currently all identical.
This code displays a bitmap from Image1 on even pages of SRichViewEdit1, at the top left corner of the main text area.
The picture is scaled by 0.5 (see Scale constant)
Code: Select all
procedure TForm3.SRichViewEdit1PaintPage(Sender: TObject; PageNo: Integer;
PageRect, R: TRect; Canvas: TCanvas; Prepaint, Printing: Boolean);
const Scale = 0.5;
begin
if Prepaint and ((PageNo mod 2) = 0) then
RV_PictureToDevice(Canvas,
PageRect.Left+SRichViewEdit1.LeftMargin100Pix,
PageRect.Top+SRichViewEdit1.TopMargin100Pix,
Round(Image1.Picture.Bitmap.Width*Scale),
Round(Image1.Picture.Bitmap.Height*Scale),
nil, Image1.Picture.Bitmap, False, SRichViewEdit1.RichViewEdit.Style.GraphicInterface);
end;
Typecasting to TCustomMainPtblRVData is wrong, this kind on RVData exists only in TRVPrint and TRVReportHelper. ScaleRichView does not use a printer resolution explicitly, so "sad" object can be nil.
As for GraphicInterface object, and object from any RVStyle can be used, they are currently all identical.
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Try this code:
In the new version, it paints below the text.
If in your version it paints above the text, all what I can suggest is upgrading.
Code: Select all
procedure TForm3.SRichViewEdit1PaintPage(Sender: TObject; PageNo: Integer;
PageRect, R: TRect; Canvas: TCanvas; Prepaint, Printing: Boolean);
begin
if Prepaint then begin
Canvas.Brush.Color := clRed;
Canvas.FillRect(PageRect);
end;
end;
If in your version it paints above the text, all what I can suggest is upgrading.
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
You should convert png to TBitmap.
If this picture is too large and it slows down editing, you can use Printing parameter of OnPaintPage: draw it only if Printing=True.
Sorry, I do not know how it can happen that a picture is below text on the screen but above text on printing. I cannot reproduce it. May be the problem is in your printer's driver...
If this picture is too large and it slows down editing, you can use Printing parameter of OnPaintPage: draw it only if Printing=True.
Sorry, I do not know how it can happen that a picture is below text on the screen but above text on printing. I cannot reproduce it. May be the problem is in your printer's driver...
sergey ok, managed to get a solution. I appreciate all the help.
My question now is another, wanted to know if the possibility of taking the function header that replicates the same text for all pages exists. I want to use only the header of page 1, for example, and would not want to use the paintpage.
it exists?
My question now is another, wanted to know if the possibility of taking the function header that replicates the same text for all pages exists. I want to use only the header of page 1, for example, and would not want to use the paintpage.
it exists?