Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - WPF Image source real size?

 
 
Old 04-11-2007   #1 (permalink)
JN1974


 
 

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 SpecsSystem Spec
Old 04-11-2007   #2 (permalink)
Plamen Ratchev


 
 

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 SpecsSystem Spec
Old 04-12-2007   #3 (permalink)
JN1974


 
 

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 SpecsSystem Spec
Old 04-12-2007   #4 (permalink)
Plamen Ratchev


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Image size in HTML Live Mail
Image size Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46