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. xargs命令学习

    1.xargs复制文件 目录下文件结构为: . ├── demo1 │ ├── test.lua │ ├── test.php │ └── test.txt └── demo2 执行命令: find ...

  2. 【pc杂谈】win7系统通过虚拟网卡共享wifi

    用管理员权限进入dos命令行 启用并设定虚拟WiFi网卡:netsh wlan set hostednetwork mode=allow  ssid=paulnet key=paulwinflo(注意 ...

  3. lodop打印控件需要开启的几个计算机服务

    首先要开启: 其次:

  4. (转)为C# Windows服务添加安装程序

    本文转载自:http://kamiff.iteye.com/blog/507129 最近一直在搞Windows服务,也有了不少经验,感觉权限方面确定比一般程序要受限很多,但方便性也很多.像后台运行不阻 ...

  5. [转]iis 重新安装后 重新注册asp.net

    iis 重新安装后 重新注册asp.net 服务器IIS问题: 卸载并重新安装了IIS.... 解决方法:原因是IIS重装后要重新安装一下.NET Framework. 开始-->运行--> ...

  6. 32位ubuntu14.04手动编译hadoop2.6.0

    下载官方编译好的包安装老是报错:Unable to load native-hadoop library for your platform 用file命令查看发现官方包里的libhadoop.so. ...

  7. 浏览器禁用Cookie

    做JavaWeb的都知道Session的底层是使用Cookie来实现的,服务器端会在本地文件中保存session信息,并将sessionID发给客户端(浏览器),浏览器就会把这个sessionID(准 ...

  8. leetcode917

    class Solution { public: string reverseOnlyLetters(string S) { int len = S.length(); queue<char&g ...

  9. PS7.0快捷键和使用技巧

    选择工具:矩形.椭圆选框工具 [M]裁剪工具 [C]移动工具 [V]套索.多边形套索.磁性套索 [L]魔棒工具 [W] 编辑工具:修复画笔.修补工具 [J]画笔.铅笔工具 [B]橡皮图章.图案图章 [ ...

  10. JSF - Access Managed-Bean in a servlet

    When you have to access your Managed Bean in a servlet, it depends on the scope you set for the Bean ...