简体   繁体   English

在页面之间传递“透明”图像

[英]Pass “transparent” image between pages

How can I pass images between pages with transparent background, png format? 如何在具有透明背景,png格式的页面之间传递图像? Now I passed image but background is black. 现在我通过了图像,但是背景是黑色的。

Here is my code: 这是我的代码:

First page: 第一页:

WriteableBitmap wb = new WriteableBitmap(logoQrCodeImage, null);
Byte[] array = ConvertImage.ConvertToBytes(wb);
if (!IsolatedStorageSettings.ApplicationSettings.Contains("State"))
{
    IsolatedStorageSettings.ApplicationSettings["State"] = array;
    IsolatedStorageSettings.ApplicationSettings.Save();
}

Second page: 第二页:

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();
ExtendedImage myImage;
myImage = wb.ToImage();
encoder.Encode(myImage, stream);

icon.Source = myImage.ToBitmap();
IsolatedStorageSettings.ApplicationSettings.Remove("State");
IsolatedStorageSettings.ApplicationSettings.Save();

You seem to encode/decode the image as JPEG, which does not handles transparency. 您似乎将图像编码/解码为JPEG,无法处理透明度。

Try saving it as-is (Bitmap) or PNG. 尝试按原样(位图)或PNG保存它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM