【发布时间】:2018-09-04 04:57:05
【问题描述】:
我有一个 WPF 的奇怪问题,我在运行时从磁盘加载图像并将它们添加到 Canvas 容器中。我的图像大小超过 20MB。我需要在一个窗口中显示 20 到 30 张图像,并且我想以完全清晰的方式显示图像。我的问题是一些图像没有显示。下面是我的代码
for (var i = 0; i < Count; i++)
{
BitmapImage bmp=new BitmapImage(new Uri(ImagePath, UriKind.RelativeOrAbsolute));
Image imageControl = new Image();
imageControl.Source = bmp;
MyCanvas.Children.Add(imageControl);
}
【问题讨论】:
-
“图像大小超过 20MB” - 这到底是什么意思?它是否是 JPG 文件的大小,表示图像超过 20 兆像素?请注意,您不应在后面的代码中创建 Image 元素。相反,在 ItemTemplate 中使用带有 Image 元素的 ItemsControl,并将其 ItemsSource 绑定到文件路径字符串的集合,例如像这样:stackoverflow.com/a/34557467/1136211
标签: wpf