System.Drawing.Image爲FromFile和ToFile提供了易於使用的方法。什麼是Silverlight BitmapImage的等價物?我正在嘗試加載並保存一個jpeg圖像作爲單元測試的一部分。該字節必須匹配正好才能通過。這是我目前的猜測:什麼是FromFile和ToFile相當於BitmapImage?
//I am not sure this is right
private BitmapImage GetImage(string fileName)
{
BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
using (Stream imageStreamSource = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
bitmapImage.BeginInit();
bitmapImage.StreamSource = imageStreamSource;
bitmapImage.EndInit();
}
return bitmapImage;
}
private void SaveImage(BitmapImage bitmapImage, string file)
{
//How to do this?
}
什麼是DecodePixelWidth? – 2010-08-06 13:26:22
來自msdn代碼片段中的註釋(第一個鏈接)「要保存重要的應用程序內存,請將圖像源的BitmapImage值的DecodePixelWidth或DecodePixelHeight設置爲所需渲染圖像的高度和寬度。如果您不這樣做這樣,應用程序將緩存圖像,就好像它被渲染爲其正常尺寸,而不僅僅是顯示的尺寸。「 – Gishu 2010-08-06 15:46:11