Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WriteableBitmap and DPI confusion

$
0
0

Hello all. I'd like to create a WriteableBitmap object that I can then assign to an "Image" control. I need to be able to (repetitively) alter the actual physical pixels in a 1:1 fashion in the Image control i.e. I don't want the system to perform any scaling. To do this, I'm querying the Image control's "ActualWidth" and "ActualHeight" properties and determining the height/width in pixels as follows:

HwndSource windowHandleSource = PresentationSource.FromVisual(this) as HwndSource;
PixelHeight = (Int32)Math.Round(image1.Height * windowHandleSource.CompositionTarget.TransformToDevice.M22);
PixelWidth  = (Int32)Math.Round(image1.Width * windowHandleSource.CompositionTarget.TransformToDevice.M11);

I then create a WriteableBitmap of dimensions PixelHeight x PixelWidth...but I'm confused about the dpiX and dpiY arguments I need to pass into the WriteableBitmap constructor. Should these arguments be:

Double DpiX = 96.0 * windowHandleSource.CompositionTarget.TransformToDevice.M11;
Double DpiY = 96.0 * windowHandleSource.CompositionTarget.TransformToDevice.M22;

?

Again, I'm just trying to generate a WriteableBitmap object to assign to an "Image" controls "Source" property such that I can perform a 1:1 pixel alteration for monitors of various dpi. Thanks in advance.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>