![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | WPF Image source real size? Hi, Has anybody found out how to get the real size from image source's graphic file. For some reason if I do like this: BitmapImage Dummy; Uri UriTarget = new Uri(FileName); Dummy = new BitmapImage(); Dummy.BeginInit(); Dummy.UriSource = UriTarget; Dummy.EndInit(); FrameImage.Source = Dummy; And check FrameImage.Source.Width or Height, it's 3.5 times smaller than the real image size? I have done this in XAML: <Image Opacity="1" Name="FrameImage" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="None"> So it shouldn't stretch it, but it does still seem to change the size automatically. Where that scaling factor comes, can I turn it off, or can I calculate the original image size from somewhere? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: WPF Image source real size? The ButtonImage class has the PixelWidth and PixelHeight properties that will give you the bitmap pixel width and height. The DpiX and DpiY values will give you the resolution (in dots per inch). Then the properties Width and Height are calculated based on the formulas below: Width = (96 * PixelWidth) / DpiX Height = (96 * PixelHeight) / DpiY The Width and the Height are the metric size of the bitmap in device independent units (the 96 converts inches into device independent units). And the 96 comes from Windows running in 96dpi by default with Normal Fonts, so that is considered the normal size for a pixel. HTH, Plamen Ratchev http://www.SQLStudio.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: WPF Image source real size? Actually what I was looking for was this: BitmapSource SourceData = (BitmapSource)FrameImage.Source; Then I could read the real picture size from SourceData.PixelHeight and SourceData.PixelWidth Thanks for pointing me to the right direction! -Jani "Plamen Ratchev" wrote: > The ButtonImage class has the PixelWidth and PixelHeight properties that > will give you the bitmap pixel width and height. The DpiX and DpiY values > will give you the resolution (in dots per inch). Then the properties Width > and Height are calculated based on the formulas below: > > Width = (96 * PixelWidth) / DpiX > > Height = (96 * PixelHeight) / DpiY > > The Width and the Height are the metric size of the bitmap in device > independent units (the 96 converts inches into device independent units). > And the 96 comes from Windows running in 96dpi by default with Normal Fonts, > so that is considered the normal size for a pixel. > > HTH, > > Plamen Ratchev > http://www.SQLStudio.com > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: WPF Image source real size? Yes, this works too. I had a typo: ButtonImage should be BitmapImage. The BitmapImage inherits the read-only properties PixelWidth and PixelHeight from BitmapSource, so you can use then directly with your BitmapImage. Plamen Ratchev http://www.SQLStudio.com |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Image size in HTML | Live Mail | |||
| Image size | Vista music pictures video | |||