Solved

Getting HBITMAP from TControlCanvas

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

Expert Comment

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 112
Error E2158 compiling with Delphi XE10 Seattle 2 112
Multiple image collision 13 80
Graphics32 under Delphi 10.1 Berlin 2 101
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 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