Get Image Resolution

Hello everybody,

is there a way to get an image resolution in clarion?
now I am using vbscript “oImage.HorizontalResolution” as a work around from my clarion application but frankly I am not satisfied with it.

thank you.

Are you talking about before you load the image into an image control, or after?

For a Clarion image, you can set PROP:Pixels on the window, create a hidden IMAGE control, set PROP:NoWidth and PROP:NoHeight, load your image file, and read PROP:Height/PROP:Width.

Here’s an example of reading a PNG height/width without loading the entire image.
https://www.nettalkcentral.com/forum/index.php?topic=8516.0

thank you for your rapid reply. actually it doesn’t matter if it is after or before as the reason I need this is that I have thousands of images and I want to separate the low resolution images from the other images.

thanks again

it is ok for width and height but still I cant get the resolution.

any more suggestions is highly appreciated.

regards

Width * Height = total pixels

Really sorry I was not clear from the beginning. what I was thinking of resolution in dpi as a result.

Thank you for your help.

Regards

Pretty sure that most raster images probably don’t have a dpi/ppi (or whatever unit of measure) stored in it. PNG has an optional place to store that. The more dots, the more resolution. The number of those dots that you fit into an inch, cm, etc, is your DPI/PPI/PPC/WTH.
I envision a DPI in a PNG would be more like a suggestion/default. But if you scale the image to different dimensions on its canvas, now your DPI is different. There’s an x-axis value and y-axis value. I don’t think they are required to be equal.
DPI/PPI is important during the process of acquiring via a scanner or preparing for print or within photoshop or something.

Another way to obtain image resolution without loading the entire image is GdiPlus api: mikeduglas/GdiPlus: GdiPlus support (github.com)

1 Like

Neat-o. Is there a list of what kind of images are supported or not supported?

I believe there is :slight_smile:

I really appreciate your neat example, but I’m a little confused.

Does LoadImageFromFile not read the entire image into memory?

That’s the thing I’m trying to avoid, for my purposes. e.g., if someone uploads a huge image to my server, I want to determine first whether it will fit within the limits of the my apps specification before attempting to load it. That’s why my example just reads xx bytes of a PNG to examine the header.

Thanks again Mike

Oh sorry Jeff, LoadImageFromFile definitely does load the entire image, what I meant it is not required to load it into an Image control. GdiPlus has the ability to read image metadata (supported formats are TIFF, JPEG, Exif, and PNG), I will try to implement this feature.

1 Like

You can use ClarionFreeImage - FreeImageClass.iImage.GetDotsPerMeterX

Clarion FreeImage Project - Download

Well in GdiPlus you first load the image, then read metadata.

GdiPlus can return dpi values, now my example shows it:

Image c:\Clarion\Clarion11.1\Images\cwwall.bmp, resolution in pixels 168x180, dpi 72
Image c:\Clarion\Clarion11.1\Images\softvelocity.gif, resolution in pixels 150x84, dpi 96
Image c:\Clarion\Clarion11.1\Images\DISKCOPY.ICO, resolution in pixels 32x32, dpi 96
Image c:\Clarion\Clarion11.1\Images\sv_small.jpg, resolution in pixels 110x60, dpi 72
Image c:\Clarion\Clarion11.1\Images\AnyScreen.png, resolution in pixels 333x319, dpi 150

I will check it. thanks

I already have it but I gave a quick look and did not find how to get the resolution. I will check again more deeper.
thanks

Hi,
I tried to run it in C6 by recreating the project but I got an error ‘winapi.inc not found’.
and I tried to open it with C9 but I get the error ''Cannot read Microsoft solution file format 12.00.

thank you

winapi is here.
Don’t open C11 project in C9, just create new one.