在WPF中更改BitMapImage的尺寸,以及可以在< Image>中放置什么样的对象?元素? [英] Changing the dimensions of a BitMapImage in WPF, and what kind of objects can I put in an <Image> element?

查看:58
本文介绍了在WPF中更改BitMapImage的尺寸,以及可以在< Image>中放置什么样的对象?元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 TreeView 元素创建一个资源管理器应用,并且对于树的每个级别都有不同的图标,并在此处关注以下文章:

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-Tree

一切正常,除了我也希望拥有不同的大小图标.

It is all working great, except that I want to have different sized icons as well.

我的Image元素的 XAML 在这里:

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;
}

如何更改要返回的图像的尺寸?更改bitmapimage对象的尺寸似乎不起作用.我还可以返回其他哪些图像对象?

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?

推荐答案

好,我想出了我的问题.哎呀,真是个假人.下面是我更改的代码,这些代码使我获得了想要的结果:

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;

这篇关于在WPF中更改BitMapImage的尺寸,以及可以在&lt; Image&gt;中放置什么样的对象?元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆