<!-- Simple image rendering. However, rendering an image this way may not
result in the best use of application memory. See markup below which
creates the same end result but using less memory. -->
<Image Width="200" Source="Sample.jpg"/>
其中,
Sample.jpg
是一张分辨率为 7360 x 4912 的图片。启动后的程序内存占用 534 MB。
<Image Width="200">
<Image.Source>
<!-- To save significant application memory, set the DecodePixelWidth or
DecodePixelHeight of the BitmapImage value of the image source to the desired
height and width of the rendered image. If you don't do this, the application will
cache the image as though it were rendered as its normal size rather than just
the size that is displayed. -->
<!-- Note: In order to preserve aspect ratio, only set either DecodePixelWidth
or DecodePixelHeight but not both. -->
<BitmapImage DecodePixelWidth="200" UriSource="Sample.jpg" />
</Image.Source>
</Image>
C# 开发者、跨境电商从业人员。
上一篇
开发 WPF 程序时,限制一次只能打开一个程序。
下一篇
在 PostgreSQL 中获取两列的最大、最小值