15,919,434 members
2.00/5 (1 vote)
See more:
I have an image I need to center on the print page. It's size is in pixels and I have to convert it first to inches. How do you convert from pixels to inches?
Posted

## Solution 2

This can be done by using the Height and VerticalResolution of the image you're trying to print.

The following article describes this as the calculation:

C#
```float imageHeightPrint = imageToPrint.Height /
imageToPrint.VerticalResolution * 100;```

http://stackoverflow.com/questions/796993/transform-pixel-height-of-image-to-printing-size-used-by-graphics-object[^]

Al Yambo 7-Jun-12 8:33am
Thank you Stephen. The VerticalResolution and HorizontalResolution are all I needed as it gives the conversion in pixels/inch.

## Solution 3

Hi try this Code, I am not sure ,hope it may work for you

CSS
```Image fullSizeImg = null;
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes);
fullSizeImg = Image.FromStream(ms, true);
System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(700, 800, dummyCallBack, IntPtr.Zero);
thumbNailImg.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Png);
fullSizeImg.Dispose();
thumbNailImg.Dispose();```

Al Yambo 7-Jun-12 8:29am

## Solution 4

Thank you Stephen for giving the right answer and link. This is just a clarification post.

Image newImage = Image.FromFile("c:\\Documents\\pic.gif");

newImage.HorizontalResolution and newImage.VerticalResolution gives the conversion in pixels/inch. So if your horizontal measurement is for example 238 pixels and the horizontal resolution is 96 pixels/inch then
238 pixels*(inch/96 pixels)= 2.4792 inch. However I had to multiply by 100 (2.4792 X 100) since I guess the default units for the print page are in hundred inches. Like a normal size typewritting paper would be 850 X 1100 instead of 8.5 X 11.

I can then use this measurements and the page measurements to center the image on the print page.

as in:

// Create Point for upper-left corner of image.
Point ulCorner = new Point(xpos, ypos);

// Draw image to screen.
g.Graphics.DrawImage(newImage, ulCorner);

LenuIndia 4-Jul-17 13:07pm
I am Using vb.net, I need fix measurement [width= 3.375” x Height = 2.125“]

different images here
image 1 size width = 4500, Height =1393
image 2 size width = 2081, Height =1280
image 3 size width = 1081, Height =280 etc.... But