Changing the dimensions of a BitMapImage in WPF, and what kind of objects can I put in an <Image> element?
Ok, I figured out my question. Jeez, what a dummy. Below is the code I changed that got me the results I wanted:
Uri uri = new Uri("pack://application:,,,/Images/DeployWiz_Network.png");
BitmapImage source = new BitmapImage();
source.BeginInit();
source.UriSource = uri;
source.DecodePixelHeight = 10;
source.DecodePixelWidth = 10;
source.EndInit();
return source;
Related videos on Youtube
Dbloom
By day I do Windows programming in the government sector. At night I play videogames and work on house projects.
Updated on May 25, 2022Comments
-
Dbloom almost 2 years
I am trying to create an explorer app with a
TreeView
element, and have different icons for each level of the tree, and following the article here: http://www.codeproject.com/Articles/21248/A-Simple-WPF-Explorer-TreeIt is all working great, except that I want to have different sized icons as well.
My
XAML
for the Image element is here:<Image Name="img" Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}, Path=Header, Converter={x:Static local:HeaderToImageConverter.Instance}}" />
The piece of code that decides which icon to return is here:
if ((value as string).Contains(@"\"")) { Uri uri = new Uri ("pack://application:,,,/Images/DeployWiz_Network.png"); BitmapImage source = new BitmapImage(uri); return source; }
How would I change the dimensions of the image being returned? Changing the dimensions of a bitmapimage object doesn't seem to work. What other image objects could I return as the source?
-
Clemens almost 11 yearsWhy not simply set the
Width
andHeight
of theImage
control? -
Dbloom almost 11 yearsBecause depending on what level of the tree you are in, I want that to be different.
-
-
Clemens almost 11 yearsYou should not set both of
DecodePixelWidth
andDecodePixelHeight
as that may spoil the image's aspect ratio. -
secretgenes about 8 years@Dbloom: decodePixelHeight and Decodepixelwidth property doesn't work in windows 8 though it work in windows 7 and windows 10.
-
Hendra Anggrian over 7 yearsnewer version of
BitmapImage
no longer haveBeginInit()
andEndInit()
.