我需要保存bitmap
在byte[]
與C#,如何做到這一點?此如何在byte [] c#中保存位圖?
2
A
回答
7
工作的代碼是
System.Drawing.Image originalImage = dpgraphic.image;// replace your image here i.e image bitmap
//Create empty bitmap image of original size
float width=0, height=0;
Bitmap tempBmp = new Bitmap((int)width, (int)height);
Graphics g = Graphics.FromImage(tempBmp);
//draw the original image on tempBmp
g.DrawImage(originalImage, 0, 0, width, height);
//dispose originalImage and Graphics so the file is now free
g.Dispose();
originalImage.Dispose();
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
tempBmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
//dpgraphic.image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] imageBytes = ms.ToArray();
}
1
看看從MSDN http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx這個示例中,我希望你正在尋找這一點。
1
怎麼樣
在
YourByteArray = System.IO.File.ReadAllBytes("YourGraphic.bmp");
讀寫出來
System.IO.File.WriteAllBytes("SaveToFile.bmp", YourByteArray);
作品對我來說
相關問題
- 1. 如何將HTML保存爲byte []作爲圖像??? c#
- 2. 在C#中的位置保存位圖圖像
- 3. 在Android中保存位圖
- 4. 如何將一個byte []保存爲java.sql.Clob?
- 5. 如何使用程序保存byte []?
- 6. 如何保存到MFC C++應用程序中的位圖?
- 7. 如何將位圖保存爲圖標?
- 8. 如何在C#中將8位灰度圖像轉換爲byte []數組?
- 9. 將32位位圖保存爲C#中的1位.bmp文件
- 10. 通過C#在WPF中保存位圖圖像
- 11. 保存用戶在c#中繪製位圖圖形
- 12. C++位圖保存二進制標誌
- 13. 如何在Android中將位圖保存到位圖時設置dpi圖像?
- 14. 如何在C/C++中保存數據?
- 15. 如何將位圖保存到Firebase
- 16. 如何將XImage保存爲位圖?
- 17. 如何將位圖保存到Android Gallery
- 18. 保存一個畫布到位圖,然後保存位圖
- 19. 如何將文件保存爲文本文件中的Byte數組? C++
- 20. 如何在C++中保存大於64位的整數?
- 21. 如何網頁C#位圖對象保存到Server磁盤
- 22. 如何將Emgu`Image <Bgr, Byte> frame`作爲JPEG保存在內存流中?
- 23. 在Android中旋轉保存的位圖
- 24. 保存的位圖大於我讀取的位圖C#
- 25. 如何在Android中保存運行時創建的位圖?
- 26. 如何在matlab中裁剪圖像並保存位置
- 27. 如何在滾動視圖中保存滾動位置?
- 28. 如何在內存中保留一個位圖
- 29. 如何在內部存儲器上保存位圖
- 30. 位圖的Targa(TGA)保存錯誤
重複:http://stackoverflow.com/questions/268013/怎麼辦 - 我 - 轉換 - 一個位圖到字節 – Alex 2011-03-17 12:37:30