BitmapImage使用FileStream读取文件

            var bitmapImage = new BitmapImage();

            using (FileStream fs = new FileStream(file.FullName, FileMode.Open))

            {

                bitmapImage.BeginInit();

                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;

                bitmapImage.StreamSource = fs;

                bitmapImage.EndInit();

            }

            bitmapImage.Freeze();
            var img = new Image();

            img.Source = bitmapImage;

 第二种方式:

                    byte[] buffer = File.ReadAllBytes(file.FullName);

                    img.Source = new ImageSourceConverter().ConvertFrom(buffer) as BitmapSource;

http://www.hjrich.cn/chanpin_dubao.html

你可能感兴趣的:(bitmap)