當我使用此功能將圖像(從網上抓取)保存到IsolatedStorage時,我發現文件大小比我從網頁瀏覽器保存的大。如何獲得bitmapimage(jpg/png)的長度?
public static bool CreateImageFile(string filePath, BitmapImage bitmapImage)
{
//StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri(filePath, UriKind.Relative));
using (isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
string directoryName = System.IO.Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(directoryName) && !isolatedStorage.DirectoryExists(directoryName))
{
isolatedStorage.CreateDirectory(directoryName);
}
if (isolatedStorage.FileExists(filePath))
{
isolatedStorage.DeleteFile(filePath);
}
//bitmapImage
using (IsolatedStorageFileStream fileStream = isolatedStorage.OpenFile(filePath, FileMode.Create, FileAccess.Write))
{
bitmapImage.CreateOptions = BitmapCreateOptions.None;
WriteableBitmap wb = new WriteableBitmap(bitmapImage);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
fileStream.Close();
}
}
return true;
}
是否可以使用WriteableBitmap.SaveJpeg(...)保存png圖像? 是否有任何函數來獲取BitmapImage的長度?
你爲什麼要保存SaveJpeg方法PNG文件?看看PNG編碼器http://blogs.msdn.com/b/nikola/archive/2009/03/04/silverlight-super-fast-dymanic-image-generation-code-revisited.aspx – 2012-07-17 13:26:19