zoukankan      html  css  js  c++  java
  • byte[]与Image Image与 byte[] 之间的转换

    /// <summary>
    /// 将byte[]转换为Image
    /// </summary>
    /// <param name="bytes">字节数组</param>
    /// <returns>Image</returns>

    public Image ReadImage(byte[] bytes)
    {
         MemoryStream ms=new MemoryStream(bytes,0,bytes.Length);
         BinaryFormatter bf = new BinaryFormatter();
         object obj=bf.Deserialize(ms);   
      ms.Close(); 
      return (Image)obj;
    }
    /// <summary>
    /// 将Image转换为byte[]
    /// </summary>
    /// <param name="image">Image</param>
    /// <returns>byte[]</returns>

    public byte[] ConvertImage(Image image)
    {
         MemoryStream ms=new MemoryStream();
         BinaryFormatter bf = new BinaryFormatter();
         bf.Serialize(ms,(object)image);
         ms.Close();
         return ms.ToArray();
    }

  • 相关阅读:
    小的面试题
    email
    网络
    进程,线程
    周日作业
    Python_day9
    Python_day8
    假期作业
    12/13
    Python_day7
  • 原文地址:https://www.cnblogs.com/ewyb/p/2662446.html
Copyright © 2011-2022 走看看