圖片轉二進制 ,


1> 圖片轉二進制 
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 byte[] PhotoImageInsert(System.Drawing.Image imgPhoto)
{
//將Image轉換成流數據,並保存為byte[] 
MemoryStream mstream = new MemoryStream();
imgPhoto.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] byData = new Byte[mstream.Length];
mstream.Position = 0;
mstream.Read(byData, 0, byData.Length);
mstream.Close();
return byData;
}
 
2> 二進制轉圖片
public System.Drawing.Image ReturnPhoto(byte[] streamByte)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
return img;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM