[WPF]将imagesource链接到应用程序的调试文件夹 [英] [WPF] Link imagesource to the debug folder of application

查看:65
本文介绍了[WPF]将imagesource链接到应用程序的调试文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的程序中有很多矩形,里面装满了图像。我做了两种方法: -



1)从解决方案外部获取图像。应用程序将创建一个名为Images的文件夹,并将所有图像放在其上。矩形ImageSource将链接为

Hi,

I have a many rectangle in my program which be filled with image. I have done two method:-

1) Get image from outside of solution. Application will create a folder called Images and all the image are put on it. The rectangle ImageSource will link as this

<ImageBrush ImageSource="Images/Background.jpg" />



2)在exe路径上创建一个文件夹(debug)并打开选择图像。矩形ImageSource将链接为


2) Create a folder on the exe path(debug) and open choose image. The rectangle ImageSource will link as this

<ImageBrush ImageSource="/Mypp;component/bin/Debug/image/background/Background.jpg" />





我的两种方法都会制作我的exe会变大,因为exe会将图像嵌入其中。如果我将矩形空白并使用代码从任何路径对图像进行内存流处理,则需要花费一些时间来加载(看起来冻结)在我的页面上,其中一些要填充40个矩形。因此,有任何其他方法可以使exe更小,ImageSource可以像



Both of my method will make my exe become large as the exe will embed the image on it. If I blank the rectangle and use code to memorystream the image from any path, it will take time to load(looks freeze) as on my page, some of it have 40rectangle to be filled. So have any other way to make exe smaller size which the ImageSource can be like

<ImageBrush ImageSource="Debug/image/background/Background.jpg" /> 

我需要像这样,因为图片必须能够更改但保持文件名和扩展名与当前相同根据用户要求提交的文件。



所以我问任何了解技巧或有一些指导的人,请与我分享。谢谢程序员。

I need to be like this because the image must be able to change but keep the filename and extension as same as current file based from user requirement.

So I'm asking anyone who knows the tricks or have some guideline, kindly share with me. Thanks programmer.

推荐答案

尝试使用Border和Image标签,而不是使用Rectangle和ImageBrush。



设置Image标记的MaxWidth和MaxHeight属性以指定支持的最大宽度和高度。图像将缩小以适合指定的大小。



Instead of using Rectangle and ImageBrush, try using Border and Image tag.

Set MaxWidth and MaxHeight properties of the Image tag to specify the maximum width and height supported. Image will be shrink to fit in the size specified.

<Border Borderbrush="#395984" Borderthickness="2">
  <Image Source="./images/iq.png" MaxHeight="20" MaxWidth="20"></Image>
</Border>


您可以尝试缩小图像文件吗?降低分辨率,改变压缩技术等。
You could try making the image file smaller? Reduce resolution, change compression technology etc.


这篇关于[WPF]将imagesource链接到应用程序的调试文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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