【问题标题】:how to save bitmap in byte[] c#?如何将位图保存在 byte[] c# 中?
【发布时间】:2011-03-17 12:30:54
【问题描述】:

我需要用 c# 将 bitmap 保存在 byte[] 中,该怎么做?

【问题讨论】:

标签: c# bitmap byte


【解决方案1】:

这个的工作代码是

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();
}

【讨论】:

    【解决方案2】:

    怎么样

    阅读

    YourByteArray = System.IO.File.ReadAllBytes( "YourGraphic.bmp" ); 
    

    写出来

    System.IO.File.WriteAllBytes( "SaveToFile.bmp", YourByteArray ); 
    

    为我工作

    【讨论】:

      【解决方案3】:

      看看这个来自 MSDN http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx 的示例我希望你正在寻找这个。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-18
        • 2023-03-06
        • 2012-09-02
        • 2018-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多