how to put background image at runtime?

General TRichView support forum. Please post your questions here
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

how to put background image at runtime?

Post by Ceprotec »

Sergey Hello, I would like to know how to put an image in the background of the text at run time.

thanks
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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?
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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);
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

I am still not able to, would send me an example of how it would be, I would be very grateful.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post by Ceprotec »

email sent.
thanks
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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?
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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...
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Post 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?
Post Reply