• Image 和byte[]之间的转换


    1.Image 转 byte[]

    public byte[] GetByteByImage(Image image)
    {
      byte[] bt = null;
      try
      {
        if (!image.Equals(null))
        {
          MemoryStream ms = new MemoryStream();
          Bitmap bmp = new Bitmap(image);
          bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
          bt = new byte[ms.Length];
          ms.Position = 0;
          ms.Read(bt, 0, Convert.ToInt32(bt.Length));
          bmp.Dispose();
          ms.Dispose();
          ms.Close();
        }
      }
      catch (Exception ex)
      {
        throw ex;
      }
      return bt;
    }

    2.byte[] 转Image

    public Image GetImageByByte(byte[] imageBytes)
    {
      Image image = null;
      try
      {
        MemoryStream ms = new MemoryStream(imageBytes);
        ms.Write(imageBytes, 0, imageBytes.Length);
        image = Image.FromStream(ms, true);
        ms.Dispose();
        ms.Close();
      }
      catch (Exception ex)
      {
        throw ex;
      }
      return image;
    }

  • 相关阅读:
    嵌入式为什么要用Linux操作系统
    SPI 协议的理解
    跳转某指定地址、给某绝对地址赋值
    define 宏定义
    笔试--编程题
    spring 技巧集锦
    spring data jpa auditing
    spring security
    Python基础笔记
    调试EF源代码环境配置
  • 原文地址:https://www.cnblogs.com/cherious/p/6723740.html
Copyright © 2020-2023  润新知