Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set images height and width in inches?

Tags:

c#

I am trying to save an image from string.

so I want to know how I can set image height and width in inches at the time of saving the image.

my code follows for image saving :

 private void Base64ToImage(string base64String)
    {
        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();


    }
like image 681
Mou Avatar asked Dec 04 '22 21:12

Mou


1 Answers

That doesn't work. We save in pixels because an inch/cm/mile does not convert to on-screen real estate. The reason for this is that we all use different DPI settings, albeit 92 DPI seems to be one of the more common settings nowadays.

There are also varying DPI settings for printers...

To calculate the pixels from inches, you could try:

pixels = inches * someDpiSetting

but bear in mind this will not result in inches on every screen, every printout, etc.

EDIT: If you take a look at WPF you'll find that it has fantastic support for DPI, and will translate a form to the same (give or take) size regardless of DPI. Maybe that helps?

like image 72
Smudge202 Avatar answered Dec 16 '22 09:12

Smudge202