index > Windows Presentation Foundation ("Avalon") > Getting Height and Width of BitmapImage

Getting Height and Width of BitmapImage

Hello

I'm working on a little slideshow app for a bigger project where I'm creting a BitmapImage from an URL and feeding it to and ImageElement

The Image element sits inside a ViewBox with a couple of other elements so they resize themselves according to the window size. Anyway that is not importent, what is importning is that I need to be sure that the images does not resize bigger than their original size.

The BitmapImage class have the PixelWidth and PixelHeight which I've tried to use, but they seem to return 1 resulting in a VERY small image. This is what I do

BitmapImage img = new BitmapImage();

img.BeginInit();

img.UriSource = new Uri( node.GetAttribute( "Url" ) );

img.EndInit();

MyImage.Source = img;

MyImage.MaxWidth = img.PixelWidth;

MyImage.MaxHeight = img.PixelHeight;

I've tried moving where is set the MaxHeigt and MaxWidth properties around a bit, but the result is the same a very small image. I succeded getting the Height and Width using the Image class and getting getting the image from a stream but can't use an Image on ImageSource. And loading the image twice is just plain stupid :o)

So my question is how do i get the PixelWidth and Height from a BitmapImage, am i missing something?

--

Christian

 

 

sparrez

What is this pointing to?

img.UriSource = new Uri( node.GetAttribute( "Url" ) );

Is this a local Uri or a Uri from the web?

Robert A. Wlodarczyk - MSFT
reply 2

You can use google to search for other answers

 

More Articles

• Render buttons without border
• WPF Printing on Server
• How to get data from GridView
• fisheye effect transformation, is it possible?
• Animating a canvas?
• I think this is a design hole in WPF DataBinding - bound ItemsCon...
• Clocks and timelines and storyboards with video
• outlook look and field control using wpf
• ObservableCollection for IList
• Help needed in designing UI using CAB
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Is it possible to do a MasterDetail Bind
• Mousewheel Event in xaml
• SplitButton
• How to get reference of treeviewitem?
• The futher of WPF?
• I Want to know that how to Add Subitems
• Animating a ListBox Scrolling Text
• Adorner quirk
• Unable to use MatrixTransform operator t
• Introduction to XAML
• Which version of Windows Media Player fo
• how to do a TemplateBinding in code?
• Adding a footer to a GridView?
• AJAX style XAML generation on the server?
• Access sub-properties in <Setter/>

Hot Articles

• How can I get the Drawing of a Button fo
• BindingListCollectionView.CurrentChanged
• Opening .xaml file using ImageBrush in IE
• OnChildAdded/removed event
• Why Avi play failed when i change the pa
• Using an image as a repeating background
• WPF messageBox
• Set Focus / Selection to child item
• Storyboards and Threads Question
• WPF Novice Programmers Catch 22.
• AtlasControlToolkit controls in WPF!!
• Load image into richtext box
• Property trigger ExitActions
• how to access resource directory from c#
• PropertyGrid

Recommend Articles

• How to auto-size ListView column headers
• Animating the Web content of Frame?
• WPF hosting DirectX
• RC1 BUG: Extending TextBoxBase
• culture of IValueConverter.Convert method
• RichTextBox, get Insert mode?
• Layout Transformation
• September CTP dead link?
• problem using custom control library!!!
• Xaml Help with ResourceDictonary (MenuIt
• Sliding elements
• Loose XAML Template
• Layout in XAML
• Strange bug: property not initialized wi
• IsItemsHost triggerable?