[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Calculating real life width and height of a image

yosh

11/18/2004 6:31:00 AM

How can i calculate the real life width and height of a image in mm or inch using
image.width, image.height and image.verticalresolution or something?

my values are always alittle off...

Math.Round(((25.4 * image.width) / image.verticalresolution))

where 25.4 is one inch in mm afaik

does vb.net give any other type of value in verticalresolution than dpi ?
if so, how do i compensate for it ?
1 Answer

Bob Powell

11/18/2004 8:39:00 AM

0

The image width and height are a combination of the pixel size and the
resolution.

The image will have a declared resolution in dots per inch that must be used
to divide the pixel dimensions so...

Bitmap bm=(Bitmap)Image.FromFile("myimg.jpg");
SizeF imageSize=new SizeF(
(float)bm.Width / bm.HorizontalResolution,
(float)bm.Height / bm.VerticalResolution);

imageSize now contains the imperial measurements of the image. You can
convert to millimeters by multuplying by 25.4 in each direction if that's
what you need.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





<yosh@liquidzone.net> wrote in message
news:jbednRLt3Mka3AHcRVnyig@giganews.com...
> How can i calculate the real life width and height of a image in mm or
inch using
> image.width, image.height and image.verticalresolution or something?
>
> my values are always alittle off...
>
> Math.Round(((25.4 * image.width) / image.verticalresolution))
>
> where 25.4 is one inch in mm afaik
>
> does vb.net give any other type of value in verticalresolution than dpi ?
> if so, how do i compensate for it ?