我需要保存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. 如何在圖庫中保存位圖?
- 2. 如何在c#應用程序設置中保存byte []
- 3. 如何將HTML保存爲byte []作爲圖像??? c#
- 4. 如何在C++中聲明byte *(byte array)?
- 5. C#保存位圖輸出
- 6. 保存位圖圖像,如C#
- 7. 如何保存位圖
- 8. 在C#中的位置保存位圖圖像
- 9. C#將object []轉換爲byte [],但如何將字節對象保存爲byte?
- 10. 在Android中保存位圖
- 11. 如何使用程序保存byte []?
- 12. 如何將一個byte []保存爲java.sql.Clob?
- 13. 如何保存到MFC C++應用程序中的位圖?
- 14. 如何將圖像保存爲C#中的8位?
- 15. 如何將位圖保存爲圖標?
- 16. 如何在SQL中保存一個Byte數組?
- 17. 在C中保存圖形#
- 18. 問題與保存圖像在C中的特定位置#
- 19. 如何將圖形轉換爲位圖並將其保存在c#中?
- 20. 如何在C#中將8位灰度圖像轉換爲byte []數組?
- 21. 將32位位圖保存爲C#中的1位.bmp文件
- 22. C++位圖保存二進制標誌
- 23. 通過C#在WPF中保存位圖圖像
- 24. 保存用戶在c#中繪製位圖圖形
- 25. 保存byte []數組到MYSQL
- 26. 如何在wp7中保存透明背景的位圖圖像
- 27. 如何從位圖圖像保存到存儲在Android的
- 28. 如何在C/C++中保存數據?
- 29. 如何在Android中將位圖保存到位圖時設置dpi圖像?
- 30. 保存位圖時背景變黑 - C#
重複:http://stackoverflow.com/questions/268013/怎麼辦 - 我 - 轉換 - 一個位圖到字節 – Alex 2011-03-17 12:37:30