Change the DPI of a C #

0

I'm developing an app in WPF and at some point I need to convert the DPI of an image, how do I?

I'm using the class System.Windows.Media.Imaging.BitmapImage

And to load the image use the following code:

var fileUri = new Uri(openDlg.FileName);
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.None;
bitmap.UriSource = fileUri;
bitmap.EndInit();

One option would be to resize the resize in this way:

double resizeFactor = 96 / currentDpi;
int width = Convert.ToInt32(bitmap.PixelWidth * resizeFactor);
int height = Convert.ToInt32(bitmap.PixelHeight * resizeFactor);

This even works but is not working well = /

If you know a library also help: D

    
asked by anonymous 14.12.2016 / 03:12

0 answers