GetImageDPI and GetImageColors  SOLVED

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Post Reply
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

GetImageDPI and GetImageColors

Post by Dorwol »

I can't get GetImageDPI and GetImageColors to work! :(

First I call "PXCp_GetDocImageAsXCPage" to receive the "image identifier"
Then I call "PXC_GetImageDimension" to get width and height

Code: Select all

        PXC_GetImageDimension hPDF, im, iw, ih
        Debug.Print "iw: " & iw & " / ih: " & ih 
        ----> iw: 3,469072671002 / ih: 4,621786357501    <- this works!
Then I call "PXC_GetImageDPI" but the x/y result is "0"

Code: Select all

        PXC_GetImageDPI hPDF, im, lX, lY
        Debug.Print "X: " & lX & " / Y: " & lY
        ----> X: 0 / Y: 0    <- don't work!
Then I call "PXC_GetImageColors" but the result is "0"

Code: Select all

        ColorNumber = PXC_GetImageColors(hPDF, im)
        Debug.Print ColorNumber
        ----> 0    <- don't work!
What is my mistake?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: GetImageDPI and GetImageColors

Post by Ivan - Tracker Software »

Can you create a sample project that demonstrates the issue and send to us? It will help to understand the situation where these functions used.

Thanks
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: GetImageDPI and GetImageColors

Post by Dorwol »

I'm not sure, what did you mean with sample project. Because It's already enough to open your own sample project "SDKExamples\VBExamples\PDFXCDemo\VbExamp.vbp" and jump to function "Ex_Images_P1".

Now put only this three lines of code after the already exist "PXC_GetImageDimension pdf, p, iw, ih"
Dim lX As Long, lY As Long
PXC_GetImageDPI pdf, p, lX, lY
Debug.Print "X: " & lX & " / Y: " & lY
Debug.Print PXC_GetImageColors(pdf, p)
That's already all! You will see, it doesn't work! ;-(
But why?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: GetImageDPI and GetImageColors

Post by Ivan - Tracker Software »

The function "PXC_GetImageDPI" returns DPI values specified in original image. If original image had no DPI information, this function will return 0 as a DPI.
The function "PXC_GetImageColors" works for raster images, but for Vector based images (EMF, WMF, AMF) it will return 0.
As I see from your output from "PXC_GetImageDimension" (non integer values) you are using vector based images.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: GetImageDPI and GetImageColors

Post by Dorwol »

Ivan - Tracker Software wrote: you are using vector based images.
"TIFF" is no vector based image! I use only TIFFs.
Ivan - Tracker Software wrote:If original image had no DPI information
All my TIFF-files has DPI imformations. In "XnView" I see also the correct DPI-information!

BTW: All the TIFFs was scanned with your "OCR-DLL" (!).

So what is the solution?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: GetImageDPI and GetImageColors

Post by Ivan - Tracker Software »

Can you send me any of your TIFF ?
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: GetImageDPI and GetImageColors

Post by Dorwol »

I don't have TIF files as Tif Files, I have already PDF files.

So you can realy use every PDF with a already scanned image inside

For a better understandig, see the attached code
Last edited by Dorwol on Thu Mar 26, 2015 11:57 am, edited 2 times in total.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: GetImageDPI and GetImageColors

Post by Ivan - Tracker Software »

PXC_ and PXCp_ calls cannot be mixed.
If document was opened with PXCp_ReadDocumentW you cannot use it with PXC_ functions, and vice versa.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: GetImageDPI and GetImageColors

Post by Dorwol »

Ivan - Tracker Software wrote:PXC_ and PXCp_ calls cannot be mixed.
If document was opened with PXCp_ReadDocumentW you cannot use it with PXC_ functions, and vice versa.
OK, understand.

But "how" can I get Image-DPI and Image-Color from a TIF inside a PDF (from a scanned document)? :|
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: GetImageDPI and GetImageColors

Post by Ivan - Tracker Software »

DPI information is already missed because it is not stored with images in a PDF file.

As I see, you are using PXCp_GetDocImageAsXCPage. It returns the image handle (im) you can use this with Image-XChange to work with that image or you can use PXCp_SaveDocImageIntoFileW to save the image on disk and work with it with another API of your choice.

Once the matrix is returned by the function PXCp_ImageGetFromPage, you can then discover the image dimension (in points; 1 pt = 1/72 inch) on the page - in a PDF an image is placed on a page as rectangle with the dimension 1pt x 1pt scaled by the matrix.

Hope that helps
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: GetImageDPI and GetImageColors

Post by Dorwol »

OK, will try.

And how can I detect the colors please?
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: GetImageDPI and GetImageColors

Post by Ivan - Tracker Software »

if you use Image-XChange, there are functions to calculate number of colors in the image or its part.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: GetImageDPI and GetImageColors

Post by Dorwol »

Ivan - Tracker Software wrote:if you use Image-XChange, there are functions to calculate number of colors in the image or its part.
??? OK, but my question was "How"? Because I don't find any solution yet. Also not with Image-XChange! :?

So please help me!
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: GetImageDPI and GetImageColors

Post by Ivan - Tracker Software »

To use Image-XChange, you need to add the following declarations in your code:

Code: Select all

Private Declare Function IMG_PageGetSize Lib "ixclib40.dll" (ByVal page As Long, ByRef width As Long, ByRef height As Long) As Long
Private Declare Function IMG_PageGetDPI Lib "ixclib40.dll" (ByVal page As Long, ByRef xDPI As Long, ByRef yDPI As Long) As Long
Private Declare Function IMG_PageCountColors Lib "ixclib40.dll" (ByVal page As Long, ByRef pageRect As rect, ByRef numColors As Long) As Long
And now, when you have an image handle returned by this call:

Code: Select all

res = PXCp_GetDocImageAsXCPage(hPDF, ImageHandle, im)
you can get an image dimension (in pixels):

Code: Select all

Dim iwidth As Long
Dim iheight As Long
res = IMG_PageGetSize(im, iwidth, iheight)
and colors count

Code: Select all

Dim ir as rect
Dim ncolors as Long

ir.left = 0
ir.right = iwidth
ir.top = 0
ir.bottom = iheght
res = IMG_PageCountColors(im, ir, ncolors)
you can also get DPI (using IMG_PageGetDPI), but as said, images within a PDF do not store DPI information (only a JPEG may preserve this info), so, you will get 0 in most cases.

If you currently do not have license for Image-XChange, but have PRO license for the PDF-XChange SDK, please contact sales@pdf-xchange.com to get your Image-XChange license - though you can download and test it in trial mode without the license key.

HTH
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Dorwol
User
Posts: 275
Joined: Mon Aug 04, 2008 5:04 pm

Re: GetImageDPI and GetImageColors

Post by Dorwol »

Thank you!
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17822
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: GetImageDPI and GetImageColors

Post by Tracker Supp-Stefan »

:)
Post Reply