【发布时间】:2013-07-24 15:09:07
【问题描述】:
我正在使用以下函数来加载位图图像
private BitmapImage fileNameBitMap(string filePath)
{
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
try
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.DecodePixelWidth = 200;
bitmap.UriSource = new Uri(filePath);
bitmap.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
bitmap.EndInit();
image = bitmap;
return bitmap;
}
catch
{
return null;
}
}
return null;
}
当我调试 bitmap.SourceStream 时,我发现它等于 null,我还发现抛出了 FormatNotSupportedException。 在将 BitmapImage 转换为 byte[] 的过程中,我需要将 BitmapImage 存储在流中。
【问题讨论】:
-
我猜你的意思是
BitmapImage.StreamSource。当然是null,因为你还没有设置。你已经设置了UriSource。你为什么不简单地从图像文件中读取byte[](例如File.ReadAllBytes)? -
我做到了 :) 这是一个很好的解决方案,非常感谢。