Page 1 of 2
how to put background image at runtime?
Posted: Fri Jul 25, 2014 6:28 pm
by Ceprotec
Sergey Hello, I would like to know how to put an image in the background of the text at run time.
thanks
Posted: Fri Jul 25, 2014 8:40 pm
by Ceprotec
unable to resolve, but now my problem is different, it is possible to put a background image in the even-numbered pages and a different picture on odd pages?
Posted: Fri Jul 25, 2014 9:03 pm
by Sergey Tkachenko
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.
Posted: Tue Jul 29, 2014 1:36 pm
by Ceprotec
I'm doing the following:
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;
but nothing happens, what do I doing wrong?
Posted: Thu Jul 31, 2014 1:17 pm
by Ceprotec
used this in SRichViewEdit1PaintPage, this is what I want, but with the image behind the text:
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);
with RV_PictureToDevice nothing happens:
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);
Posted: Thu Jul 31, 2014 2:58 pm
by Sergey Tkachenko
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)
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;
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.
Posted: Thu Jul 31, 2014 4:26 pm
by Ceprotec
I am still not able to, would send me an example of how it would be, I would be very grateful.
Posted: Thu Jul 31, 2014 4:59 pm
by Sergey Tkachenko
I uses ActionTest SRV demo. I only placed Image1 on the form, loaded a bitmap image into it, and assigned the code above to SRichViewEdit1.OnPaintPage.
Please send me your example to richviewgmailcom, I'll find what's wrong with it.
Posted: Thu Jul 31, 2014 5:32 pm
by Ceprotec
email sent.
thanks
Posted: Fri Aug 01, 2014 1:35 pm
by Ceprotec
sergey, I could to put the picture with the last function that sent me, but the image is still in front of the text, I need him to stay behind.
thanks
Posted: Fri Aug 01, 2014 6:40 pm
by Sergey Tkachenko
Try this code:
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;
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.
Posted: Sat Aug 02, 2014 2:17 pm
by Ceprotec
sergey, I have a problem, according to the image size, the editor stays with delay.
for exemplo:
2550 x 3514,
846 KB
How do I resolve?
Posted: Sat Aug 02, 2014 3:07 pm
by Ceprotec
when I use a png image delay does not happen and the image is behind the text, but when I send to print the image is in front of the text.
only works with bitmap correct?
Posted: Sat Aug 02, 2014 7:59 pm
by Sergey Tkachenko
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...
Posted: Mon Aug 04, 2014 8:25 pm
by Ceprotec
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?