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

Image 和byte[]之间的转换的更多相关文章

  1. C# Stream 和 byte[] 之间的转换

    一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...

  2. Stream 和 byte[] 之间的转换

    Stream 和 byte[] 之间的转换 一. 二进制转换成图片 ? 1 2 3 4 5 MemoryStream ms = new MemoryStream(bytes); ms.Position ...

  3. C# Stream 和 byte[] 之间的转换(文件流的应用)

    一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...

  4. C#实现Stream与byte[]之间的转换实例教程

    一.二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream(m ...

  5. 将String转化成Stream,将Stream转换成String, C# Stream 和 byte[] 之间的转换(文件流的应用)

    static void Main( string[] args ) { string str = "Testing 1-2-3"; //convert string 2 strea ...

  6. C#下载文件,Stream 和 byte[] 之间的转换

    stream byte 等各类转换 http://www.cnblogs.com/warioland/archive/2012/03/06/2381355.html using (System.Net ...

  7. Drawable、Bitmap、byte[]之间的转换

    android在处理一写图片资源的时候,会进行一些类型的转换: 1 Drawable → Bitmap 的简单方法 ((BitmapDrawable)res.getDrawable(R.drawabl ...

  8. C#--整型与字节数组byte[]之间的转换

    using System; int  i = 123;byte [] intBuff = BitConverter.GetBytes(i);     // 将 int 转换成字节数组lob.Write ...

  9. 字符串与byte[]之间的转换

    一.  编码 同一个字符在不同的编码下会被编成不同长度的编码,比如: ACSII,每个字符对应一个字节,实际上只使用了7位,从00h-7Fh.只能表达128个字符. GB2312,中文的一种编码,每个 ...

  10. Android Drawable、Bitmap、byte[]之间的转换

    转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...

随机推荐

  1. ivy antlib shemalocation

    <?xml version="1.0" encoding="UTF-8"?> <project name="yourproject& ...

  2. Ubuntu 16.04 natural scrolling

    http://ubuntuhandbook.org/index.php/2016/05/install-ubuntu-tweak-in-ubuntu-16-04/ download ubuntu-tw ...

  3. wamp 配置多站点访问

    1:在f:\wamp\bin\apache\apache2.2.21\conf目录下打开 httpd.conf 查找到 #include conf/extra/httpd-vhosts.conf 把前 ...

  4. 进程基本-进程创建,僵尸进程,exec系列函数

    Linux系统中,进程的执行模式划分为用户模式和内核模式,当进程运行于用户空间时属于用户模式,如果在用户程序运行过程中出现系统调用或者发生中断事件,就要运行操作系统(即核心)程序,进程的运行模式就变为 ...

  5. [转]MVC 经验总结_序

    <appSettings> <add key="vs:EnableBrowserLink" value="false"/> </a ...

  6. OPENVPN2.3配置文档官方说明

    openvpn Section: Maintenance Commands (8)Index NAME openvpn - secure IP tunnel daemon. SYNOPSIS open ...

  7. Unity容器声明周期管理

    Having said that, here is a solution that you can use with the Unity container: Create some custom a ...

  8. java8时间使用小结

    //LocalDate代表一个IOS格式(yyyy-MM-dd)的日期 获取当前的日期: LocalDate localDate = LocalDate.now();//LocalDate: 表示没有 ...

  9. DSL与编译原理

    DSL:领域语言 类似于SQL的一种语言,比如自创一种语言,如何解析 可以自己实现类似于一种语言: 比如hibernate里面的sql解析就使用ANTLR 比如:http://hellojinjie. ...

  10. 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #11cpuset

    HACK #11cpuset 本节介绍控制物理CPU分配的cpuset.cpuset是Linux控制组(Cgroup)之一,其功能是指定特定进程或线程所使用的CPU组.另外,除CPU以外,同样还能指定 ...