CR的代码文本

all for learning about the world
  订阅 订阅  :: 管理

System.Windows.Media.Imageing.BItmapImage 这么用才不会占用文件

Posted on 2013-11-25 15:32  mumuliang  阅读(557)  评论(0)    收藏  举报
// Read byte[] from png file
BinaryReader binReader = new BinaryReader(File.Open(filepath, FileMode.Open));
FileInfo fileInfo = new FileInfo(filepath);
byte[] bytes = binReader.ReadBytes((int)fileInfo.Length);
binReader.Close();

// Init bitmap
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
//bitmap.DecodePixelWidth = Convert.ToInt32(w); 
//bitmap.DecodePixelHeight = Convert.ToInt32(h);  
//bitmap.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
//bitmap.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreImageCache;
bitmap.StreamSource = new MemoryStream(bytes);
bitmap.EndInit();