Solved

Getting HBITMAP from TControlCanvas

Posted on 2004-04-28
5
674 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

21 Experts available now in Live!

Get 1:1 Help Now