Tiff images do not display actual size in WPF Image control

I am working on a WPF application and should be able to show multi-page tiffs in real size, as well as fit the screen. The code that I have from another StackOverflow stream is great for showing some of them in their actual size, however the new scanned tiff files, which are about 1700 x 800, show about 600 x 400.

What I'm trying to achieve is basically a copy of how Windows Photo Viewer shows you images. You can see that they fit the screen or press a button, and, if necessary, scale to the actual size by scrolling. I have 2 tiffs that work. 1 JPEG is saved as tiff from mspaint, the other (2) is an old scanned document. 1 - 180 dpi, 32-bit depth, LZW compression and 2nd resolution unit, this was done with a digital camera. 2 - 200 dpi, 1 bit of depth, 2 resolution units, CCITT t.6 compression, it was a scanned document. Files that do not work are 300dpi, but otherwise the same as # 2.

Here is the code that I use to display the image.

// Open a Stream and decode a TIFF image Stream imageStreamSource = new FileStream("C:\\Users\\cblair\\Documents\\Visual Studio 2010\\Projects\\WpfApplication1\\WpfApplication1\\flowers.tif", FileMode.Open, FileAccess.Read, FileShare.Read); TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0]; // Draw the Image myImage.Source = bitmapSource; 

and XML

<ScrollViewer HorizontalScrollBarVisibility="auto"> <Viewbox> <Image x:Name="myImage" /> </Viewbox> </ScrollViewer>

+4
source share
1 answer

WPF takes into account dpi in the image. If you have 2 different images, both at 800x600 pixels, but one at 300 dpi and the other at 200 dpi; these two images will be displayed as different sizes in the WPF application.

Some of the reasons for this are given here .
Scott Hanselman also inquired a bit about this issue here .

+2
source

Source: https://habr.com/ru/post/1401038/


All Articles