Recent

Author Topic: Copy Virtualscreen Content  (Read 2813 times)

eraaijma

  • New Member
  • *
  • Posts: 26
Copy Virtualscreen Content
« on: December 14, 2016, 02:42:06 pm »
Hi guys,

I would like to display PDF content in my forms.
I have found components: BGRABitmap, BGRAControls and included these in my project
I have found libmuPDF.pas and included this in my project too
I have found libmuPDF.DLL and put in in the project directory
Now I can run the code. So far, so good.

After I have selected a PDF, it is loaded into the virtualscreen. If I use the sliders, I can see the whole page is there.
Problem:
 I cannot get a copy of the whole VirtualScreen Bitmap in my TImage, only the visible part.
Questions:
What would be the best way to copy the content of the virtualscreen to a Timage?
Could this be done if the virualscreen is nowhere visible?

I have enclosed some code to demonstrate my point.
« Last Edit: December 14, 2016, 02:48:40 pm by eraaijma »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11458
  • FPC developer.
Re: Copy Virtualscreen Content
« Reply #1 on: December 14, 2016, 02:56:07 pm »
Most GUI apis only draw what is visible, so it could be that the virtual screen is in the pdf dll.

You probably need to investigate how drawing now works. Maybe you can let the pdf dll draw to a sufficiently large bitmap.

eraaijma

  • New Member
  • *
  • Posts: 26
Re: Copy Virtualscreen Content
« Reply #2 on: December 14, 2016, 03:39:12 pm »
@marcov
That is strange.
The following code creates an invisible bitmap on the fly, does some painting and then shows it in a visible image. Works like a charm

Code: Pascal  [Select][+][-]
  1. function PrepCanvas(var aImage: TImage; var aCanSiz,aDocSiz,aDocMar: TPoint; var aDocSca: Double; var aMsg: String): Boolean;
  2. var lOK                           :    Boolean;
  3.     aLiBo,aReOn                   :    TPoint;
  4.     aBitmap                       :    TBitmap;
  5. begin
  6.   lOK                             :=   True;
  7.   if lOK       then lOK           :=   CalcScaleOfDocu(aCanSiz,aDocSiz,aDocSca,aMsg);
  8.   try
  9.     begin
  10.       aBitMap                     :=   TBitmap.Create;                                                           {create bitmap}
  11.       aBitMap.SetSize(                 aCanSiz.X, aCanSiz.Y);
  12.       {calculate centered square: canvas-size - documentsize * documentscale/2}
  13.       aLiBo.X                     :=   round((    aCanSiz.X - aDocSiz.X * aDocSca)/2);
  14.       aLiBo.Y                     :=   round((    aCanSiz.Y - aDocSiz.Y * aDocSca)/2);
  15.       aReOn.X                     :=   round((    aCanSiz.X - aDocSiz.X * aDocSca)/2)+ round(aDocSiz.X*aDocSca);
  16.       aReOn.Y                     :=   round((    aCanSiz.Y - aDocSiz.Y * aDocSca)/2)+ round(aDocSiz.Y*aDocSca);
  17.       {step 1: clear whole of canvas-area}
  18.       aBitMap.Canvas.Brush.Color  :=   clSilver;
  19.       aBitMap.Canvas.FillRect(         0,0,      aCanSiz.X,aCanSiz.Y);
  20.       {step 2: paint shadow of later drawing}
  21.       aBitMap.Canvas.Brush.Color  :=   clGray;
  22.       aBitMap.Canvas.FillRect(         aLiBo.X+2,aLiBo.Y+2,aReOn.X+4,aReOn.Y+4);
  23.       {step 3: paint drawing area}
  24.       aBitMap.Canvas.Brush.Color  :=   clWhite;
  25.       aBitMap.Canvas.FillRect(         aLiBo.X-2,aLiBo.Y-2,aReOn.X-4,aReOn.Y-4);
  26.       {step 4: Calcluate origin of drawing}
  27.       aDocMar.X                   :=               ceil((aCanSiz.X - round(aDocSiz.X * aDocSca))/2) - 4;
  28.       aDocMar.Y                   :=   aCanSiz.Y - ceil((aCanSiz.Y - round(aDocSiz.Y * aDocSca))/2) - 4;
  29.       {step 5: Display bitmap in Image}
  30.       if lOK   then                    aImage.Picture.Bitmap.Assign(aBitmap);
  31.       FreeAndNil(aBitMap);
  32.     end;
  33.   except
  34.     on e:Exception do
  35.     begin
  36.       lOK                         :=   False;
  37.       aMsg                        :=  'fout met CanvasVulling ' + e.Message;
  38.     end;
  39.   end;
  40.   Result                          :=   lOK;
  41. end;

eraaijma

  • New Member
  • *
  • Posts: 26
Re: Copy Virtualscreen Content
« Reply #3 on: December 21, 2016, 05:00:37 pm »
Solved!
Scaling the VirtualScreen solved the problem.

Attached a test program. Double click the canvas or drop a PDF, a DXF and a pixel-graphic.
- Right-Mouseclick the centre of the canvas to repaint after resizing
- Right-Mouseclick the right of the canvas to see the next PDF page
- Right-Mouseclick the left of the canvas to see the previous PDF page

This program needs to have BGRABitmap and BGRAControls installed.
This program also needs libmupdf.dll.



 

TinyPortal © 2005-2018