日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

WPF中的Bitmap与byte

發布時間:2025/3/16 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF中的Bitmap与byte 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
WPF中的Bitmap與byte 原文:WPF中的Bitmap與byte

public MainWindow(){InitializeComponent();byte[] b = GetPictureData(@"F:\WPF\TestSolution\TestReatByteFromDB\Images\123.png");BitmapImage myimg = ByteArrayToBitmapImage(b);this.testImg.Source = myimg;}public byte[] GetPictureData(string imagepath){/**/根據圖片文件的路徑使用文件流打開,并保存為byte[] FileStream fs = new FileStream(imagepath, FileMode.Open);//可以是其他重載方法 byte[] byData = new byte[fs.Length];fs.Read(byData, 0, byData.Length);fs.Close();return byData;}public BitmapImage ByteArrayToBitmapImage(byte[] byteArray){BitmapImage bmp = null;try{bmp = new BitmapImage();bmp.BeginInit();bmp.StreamSource = new MemoryStream(byteArray);bmp.EndInit();}catch{bmp = null;}return bmp;}public byte[] BitmapImageToByteArray(BitmapImage bmp){byte[] byteArray = null;try{Stream sMarket = bmp.StreamSource;if (sMarket != null && sMarket.Length > 0){//很重要,因為Position經常位于Stream的末尾,導致下面讀取到的長度為0。 sMarket.Position = 0;using (BinaryReader br = new BinaryReader(sMarket)){byteArray = br.ReadBytes((int)sMarket.Length);}}}catch{//other exception handling }return byteArray;}

  

posted on 2019-04-25 14:08 NET未來之路 閱讀(...) 評論(...) 編輯 收藏

轉載于:https://www.cnblogs.com/lonelyxmas/p/10768117.html

總結

以上是生活随笔為你收集整理的WPF中的Bitmap与byte的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。