我需要保存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