本文介绍了BitmapImage DecodePixelWidth奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

当显示大量图像时,我遇到了一些性能问题,我发现问题是当我只需要小于大小的1/4的图像时,便使用了全分辨率图像.因此,我在BeginInit和EndInit之间添加了一条线,以将DecodePixelWidth设置为200,这是我在布局中所需的最大宽度.我的表现不再是问题,但是某些图像确实很小,绝对没有200像素宽.大多数图像似乎都能正确显示,似乎没有任何韵律或原因使它们太小而不能正常工作.我认为这可能是由于图像原始尺寸的差异,但结果没有规律.我尝试将宽度增大到600,然后让有问题的图像以200的正确宽度显示,但随后性能下降.

I was experiencing some performance issues when displaying a large number of images, I discovered the issue was that the full resolution image was being used when I really only needed an image less than 1/4 of the size. So I added a line in between BeginInit and EndInit to set the DecodePixelWidth to 200 which is the max width I will need in my layout. My performance was no longer an issue but some of the images are really small, definitely nowhere close to 200 pixels wide. Most of the images seemed to display correctly, and there doesn't seem to be any rhyme or reason to which are too small and which work correctly. I thought it might be due to differences in the original dimensions of the images but there was no pattern to the results. I tried bumping the width up to 600 which then allowed the offending images to display at the correct width of 200 but the performance then suffers.

在这一点上,我什至不知道从哪里开始寻找,并且真的很感激朝着正确的方向前进.

At this point I am not even sure where to start looking, and would be really grateful for a kick in the right direction.

以下有关图像以及我如何使用它们的更多信息.

Some more information below about the images and how I am using them.

大多数图像都在1000X1500左右,尽管有些图像的尺寸很奇怪,例如1000x1513.所有图像均为JPEG.目前,每张图片都放置在我设计的自定义用户控件中,没有什么花哨的只是它周围的背景和一些文本.然后,将每个用户控件放在其自己的行/列的网格中.网格位于滚动查看器内部,因此用户可以滚动列表.这可能不是完成我要寻找的东西的最佳方法,但是它是我很快想到的,并且在大多数情况下都有效.如果能以更简单或更简洁的方式实现我想要的功能,我很乐意切换到另一种显示方式.

Most of the images are around 1000X1500 although some have odd dimensions like 1000x1513. All of the images are JPEG. Currently each image is placed in a custom user control that I designed, nothing too fancy just a background around it with some text. Each user control is then placed in a grid, in its own row/column. The grid is inside a scrollviewer so the user can scroll through the list. This might not be the best way to accomplish what I am looking for but its what I came up with quickly and it works for the most part. Id be happy to switch to another method of display if it would accomplish what i want in an easier or more concise way.

预期结果是用于电影浏览应用程序的.电影将有一个可滚动的列表,每个列表都以其自己的图块表示,并包含标题,电影海报,流派信息,评分和说明.该列表将在各种项目上进行排序.有关电影的信息存储在另一台计算机上的sql数据库中.这些图像最初存储在另一台计算机上,但是在本地复制以提高性能.

The intended result is for a movie browsing app. There will be a scrollable list of movies, each represented as its own tile complete with title, movie poster, genre info, rating, and description. This list will be sortable on various items. The information about the movies is stored in a sql database on another machine. The images are originally stored on another machine but are copied locally to improve performance.

我已经能够通过不使用DecodePixelWidth来解决该问题,而是以所需的大小保存图像的副本,从而提高了性能.Youngjae关于不使用DecodePixelWidth的建议,以及他提到使用虚拟化列表的建议,使我获得了以下有关创建虚拟化包装面板的文章集,该文章应解决任何其他性能问题.这篇文章是针对Silverlight的,但是据我了解,silverlight基本上是wpf的精简版,如果它在Silverlight中工作,则应该在wpf中工作.转换为我使用并不难.

I have been able to solve the issue by not using DecodePixelWidth and instead saving a copy of the image at the desired size, this has improved performance. Youngjae's recommendation of not using DecodePixelWidth along with his mention of using a virtualized list led me to the following set of articles on creating a Virtualized Wrap Panel which should solve any other performance issues. The article is for silverlight but from what I understand silverlight is basically a watered down version of wpf, if it works in silverlight it should work in wpf. It shouldn't be too difficult to convert it for my use.

第1部分-MeasureOverride

第2部分-ArrangeOverride

第3部分-动画

第4部分-虚拟化

推荐答案

MSDN链接,您可以找到以下单词.

In MSDN link, you can find words as below.

而且,由于上述原因,我建议您不要使用DecodePixelWidth来调整大小.

And, I recommend you NOT to use DecodePixelWidth for resizing purpose because of the above reason.

我不知道您的原始图像大小和格式,但是不足以与虚拟列表和< Image Width ="200" Stretch ="Uniform"> 一起使用吗?

I don't know your original image sizes and formats, but isn't it enough to use with virtualized list and <Image Width="200" Stretch="Uniform">?

这篇关于BitmapImage DecodePixelWidth奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:25