2013-11-24 21 views
0

如何在具有透明背景,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(); 
ExtendedImage myImage; 
myImage = wb.ToImage(); 
encoder.Encode(myImage, stream); 

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

回答

0

你似乎編碼/圖像爲JPEG,它不處理的透明度進行解碼。

嘗試保存原樣(位圖)或PNG。

+0

但是如何將此圖像另存爲PNG?任何線索? – user2962457

+0

您需要使用第三方庫,例如ImageTools(http://imagetools.codeplex.com/)。 –

+0

好吧,我要試試。但我不知道如何在頁面之間傳遞此圖像,因爲它應該以字節爲單位。 – user2962457