我在页面之间传递图像。但在第二页上,我想将图像转换为带有透明背景的png。 最后我想分配转换后的图像到图像控件,但我有隐式转换类型的错误。将jpg转换为png并分配给图像控件
这里是我的代码:
第一页:
WriteableBitmap wb = new WriteableBitmap(logoQrCodeImage, null);
Byte[] array = ConvertImage.ConvertToBytes(wb);
if (!IsolatedStorageSettings.ApplicationSettings.Contains("State"))
{
IsolatedStorageSettings.ApplicationSettings["State"] = array;
IsolatedStorageSettings.ApplicationSettings.Save();
}
第二页:
Byte[] array = IsolatedStorageSettings.ApplicationSettings["State"] as Byte[];
MemoryStream stream = new MemoryStream(array);
WriteableBitmap wb = new WriteableBitmap(50, 50);
//wb.LoadJpeg(stream);
var encoder = new PngEncoder();
MemoryStream pngStream = new MemoryStream();
ExtendedImage myImage;
myImage = wb.ToImage();
encoder.Encode(myImage, stream);
icon.Source = myImage; //ERROR
IsolatedStorageSettings.ApplicationSettings.Remove("State");
IsolatedStorageSettings.ApplicationSettings.Save();
我使用ImageTools库。
错误消息:
错误1无法隐式转换类型 'ImageTools.ExtendedImage' 到 'System.Windows.Media.ImageSource'
现在图像模糊完全错误发送。像不同颜色的相同线条。 – user2962457
我有这个:[Image](http://i.imgur.com/9iiIWBJ.jpg) – user2962457
我会使用WriteableBitmapEx中提供的ToByteArray扩展方法,然后使用FromByteArray方法。 –