Solved

Getting HBITMAP from TControlCanvas

Posted on 2004-04-28
5
677 Views
Last Modified: 2013-12-03
I am using the Adobe AcroExch OLE interface to extract page images of a PDF document using the PDPAGE.CopyToClipboard function. The clipboard bitmap is then converted to a TIF file using a third party graphics library.

This works fine but is painfully slow at approximately 1 page per 3 seconds.  We have over 1,000,000 pages to convert.

I have another utility, XPDFRasterizer, that is ten times faster that AcroExch but it has a problem with rendering Adobe Master Fonts so I have had to abandon it.

However, I have done some tests using the AcroExch DrawEx function instead of CopyToClipboard and it is also very fast. However, it only works by drawing the PDF page bitmap onto a TForm.Canvas.

The graphics library requires 2 parameters, HBITMAP, HPALETTE or HDC.  My problem is to get a HBITMAP from TForm.Canvas without doing a CopyRect.

Any ideas?

Roger Fedyk

0
Comment
Question by:rfedyk
  • 2
  • 2
5 Comments
 
LVL 3

Assisted Solution

by:MikProg
MikProg earned 250 total points
ID: 10946010
>get a HBITMAP from TForm.Canvas without doing a CopyRect
I don't understand precisely what you need. But bitmap handle in device context of TForm.Canvas can be created

HBITMAP CreateCompatibleBitmap(

    HDC hdc,      // handle to device context
    int nWidth,      // width of bitmap, in pixels  
    int nHeight       // height of bitmap, in pixels  
   );      
=function CreateCompatibleBitmap(DC: HDC; Width, Height: Integer): HBITMAP; stdcall;

HBITMAP CreateDIBSection(

    HDC hdc,      // handle to device context
    CONST BITMAPINFO *pbmi,      // pointer to structure containing bitmap size, format, and color data
    UINT iUsage,      // color data type indicator: RGB values or palette indices
    VOID *ppvBits,      // pointer to variable to receive a pointer to the bitmap's bit values
    HANDLE hSection,      // optional handle to a file mapping object
    DWORD dwOffset      // offset to the bitmap bit values within the file mapping object
   );      
=function CreateDIBSection(DC: HDC; const p2: TBitmapInfo; p3: UINT;
  var p4: Pointer; p5: THandle; p6: DWORD): HBITMAP; stdcall;

Take look into Graphics.pas
function CopyBitmap(Handle: HBITMAP; OldPalette, NewPalette: HPALETTE;
  var DIB: TDIBSection; Canvas: TCanvas): HBITMAP;
can show you a lot
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10946593

   HBITMAP is Handle to Bitmap ... you can't get it if you don't copy the canvas to Bitmap ...

   Form1.Canvas.Handle - it type HDC - which is handle to DeviceContext ...

   Why you don't want to use CopyRect... ?
0
 
LVL 3

Expert Comment

by:MikProg
ID: 10946803
Ivanov_G, rfedyk> I think here we have lib that works with bitmap handles so API bitmap manipluation functions reqired to create in DC DIB and use DIB handle to place picture to form. Is it?
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 250 total points
ID: 10946855
procedure TForm1.Button1Click(Sender: TObject);
var
  hBitmap : LongWord;
begin
  hBitmap := CreateCompatibleBitmap( Form1.Canvas.Handle, Form1.Width, Form1.Height);
end;
0
 
LVL 33

Expert Comment

by:Slick812
ID: 10954858
hello rfedyk, , can you show the parameters of the
DrawEx   function
??
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now