[英]how to save bitmap in byte[] c#?
我需要用c#在byte[]
保存bitmap
,怎么做?
这个的工作代码是
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();
}
怎么样
读入
YourByteArray = System.IO.File.ReadAllBytes( "YourGraphic.bmp" );
写出来
System.IO.File.WriteAllBytes( "SaveToFile.bmp", YourByteArray );
适合我
从MSDN查看此示例http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx我希望您正在寻找此项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.