Image 无法识别图像标题。Windows Phone 8应用程序中的(HRESULT:0x88982F61的异常)
这是我的密码Image 无法识别图像标题。Windows Phone 8应用程序中的(HRESULT:0x88982F61的异常),image,windows-phone-8,Image,Windows Phone 8,这是我的密码 public async Task SetLargeImageAsync(byte[] imageBytes, bool storeBytesInObject = false) { var tcs = new TaskCompletionSource<string>(); SmartDispatcher.BeginInvoke(() => { using (
public async Task SetLargeImageAsync(byte[] imageBytes,
bool storeBytesInObject = false)
{
var tcs = new TaskCompletionSource<string>();
SmartDispatcher.BeginInvoke(() =>
{
using (MemoryStream ms = new MemoryStream(imageBytes))
{
if (storeBytesInObject)
this.LargeImageBytes = imageBytes;
BitmapImage image = new BitmapImage();
image.SetSource(ms);
this.LargeImage = image;
tcs.SetResult(string.Empty);
}
});
await tcs.Task;
}
这是真的吗?解决这个问题的办法是什么 您传入的图像无效-要么已损坏,要么以WP无法本机解码的格式存储。支持的格式的完整列表可在以下位置找到:在开始操作之前确保imageBytes.Position=0。正如MarcosVasconcelos的评论中所述,对我来说,解决方案是在写入流之后,在设置BitmapImage流源之前,将MemoryStream中的位置设置为开头 例如:
public static BitmapImage CreateImage(byte[] src)
{
var img = new BitmapImage();
var strm = new System.IO.MemoryStream();
strm.Write(src, 0, src.Length);
// set the position of stream to 0 after writing to it
strm.Seek(0, System.IO.SeekOrigin.Begin);
img.BeginInit();
img.StreamSource = strm;
img.EndInit();
return img;
}
然后如何识别它是无效图像。因为我正在使用UI线程设置位图图像。我不想在发生异常时访问。如何识别它?捕获异常:)感谢您指向查找(0),解决了我的问题
public static BitmapImage CreateImage(byte[] src)
{
var img = new BitmapImage();
var strm = new System.IO.MemoryStream();
strm.Write(src, 0, src.Length);
// set the position of stream to 0 after writing to it
strm.Seek(0, System.IO.SeekOrigin.Begin);
img.BeginInit();
img.StreamSource = strm;
img.EndInit();
return img;
}