我試圖將位圖保存爲我的隔離存儲爲png文件。我在Codeplex上找到一個名爲ImageTools的圖書館,人們一直在推薦這個圖書館,但是當我嘗試它並試圖打開文件時說它已損壞。任何知道我做錯了什麼?將位圖保存爲WP7上的PNG
private static void SaveImageToIsolatedStorageAsPng(BitmapImage bitmap, string fileName)
{
//convert to memory stream
MemoryStream memoryStream = new MemoryStream();
WriteableBitmap writableBitmap = new WriteableBitmap(bitmap);
writableBitmap.SaveJpeg(memoryStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
//encode memory stream as PNG
ExtendedImage image = new ExtendedImage();
image.SetSource(memoryStream);
PngEncoder encoder = new PngEncoder();
//Save to IsolatedStorage
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var writeStream = new IsolatedStorageFileStream(fileName, FileMode.Create, store))
{
encoder.Encode(image, writeStream);
}
}
爲什麼你想先轉換成較慢的格式呢?如果圖像是JPEG格式,則不會通過將其轉換爲PNG獲得任何收益。觀看PNG比JPEG更慢。 –
格式我需要在PNG –
也許他需要透明度或無損壓縮? –