1.将图片Image转换成Byte[]

///
<summary>
       /// 将图片Image转换成Byte[]
      
/// </summary>
       /// <param
name="Image">image对象</param>
       /// <param
name="imageFormat">后缀名</param>
       /// <returns></returns>
       public static byte[] ImageToBytes(Image Image,
System.Drawing.Imaging.ImageFormat imageFormat)
       {

if (Image == null) { return null; }

byte[] data = http://www.cnblogs.com/peasana/archive/2012/02/13/null;

using (MemoryStream ms= new MemoryStream())
           {

using (Bitmap Bitmap = new Bitmap(Image))
              
{

Bitmap.Save(ms, imageFormat);

ms.Position = 0;

data = http://www.cnblogs.com/peasana/archive/2012/02/13/new byte[ms.Length];

ms.Read(data, 0, Convert.ToInt32(ms.Length));

ms.Flush();

}

}

return data;

}

2. byte[]转换成Image

/// <summary>
           /// byte[]转换成Image
          
/// </summary>
           /// <param
name="byteArrayIn">二进制图片流</param>
           ///
<returns>Image</returns>
           public static
System.Drawing.Image byteArrayToImage(byte[] byteArrayIn)
           {
              
if (byteArrayIn == null)
                  
return null;
              
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArrayIn))
              
{
                  
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
                  
ms.Flush();
                  
return returnImage;
              
}
           }

3.  Image转换Bitmap

//Image转换Bitmap

1.
Bitmap img = new Bitmap(imgSelect.Image);

2.
Bitmap bmp = (Bitmap)pictureBox1.Image;

4. Bitmap转换成Image

//Bitmap转换成Image

using System.IO;

private static System.Windows.Controls.Image Bitmap2Image(System.Drawing.Bitmap Bi)
      
{          
           MemoryStream ms =
new MemoryStream();
           Bi.Save(ms,
System.Drawing.Imaging.ImageFormat.Png);
           BitmapImage bImage
= new BitmapImage();
          
bImage.BeginInit();
          
bImage.StreamSource = new MemoryStream(ms.ToArray());
           bImage.EndInit();
           ms.Dispose();
           Bi.Dispose();
          
System.Windows.Controls.Image i = new System.Windows.Controls.Image();
           i.Source = bImage;
           return i ;
       }

5. byte[] 转换 Bitmap

//byte[] 转换 Bitmap
public static Bitmap BytesToBitmap(byte[] Bytes)
       {
           MemoryStream
stream = null;
           try
           {
              
stream = new MemoryStream(Bytes);
              
return new Bitmap((Image)new Bitmap(stream));
           }
           catch
(ArgumentNullException ex)
           {
              
throw ex;
           }
           catch
(ArgumentException ex)
           {
              
throw ex;
           }
           finally
           {
              
stream.Close();
           }
       } 
6. Bitmapbyte[] 
    //Bitmap转byte[] 
       public static byte[] BitmapToBytes(Bitmap Bitmap)
       {
           MemoryStream ms =
null;
           try
           {
              
ms = new MemoryStream();
              
Bitmap.Save(ms, Bitmap.RawFormat);
              
byte[] byteImage = new Byte[ms.Length];
              
byteImage = ms.ToArray();
              
return byteImage;
           }
           catch
(ArgumentNullException ex)
           {
              
throw ex;
           }
           finally
           {
              
ms.Close();
           }
       }
   }

Byte[]、Image、Bitmap_之间的相互转换的更多相关文章

  1. android开发之Bitmap 、byte[] 、 Drawable之间的相互转换

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

  2. Byte[]、Image、Bitmap 之间的相互转换

    原文:Byte[].Image.Bitmap 之间的相互转换 /// <summary>        /// 将图片Image转换成Byte[]        /// </summ ...

  3. Python网络编程——主机字节序和网络字节序之间的相互转换

    If you ever need to write a low-level network application, it may be necessary to handle the low-lev ...

  4. 字符编码之间的相互转换 UTF8与GBK(转载)

    转载自http://www.cnblogs.com/azraelly/archive/2012/06/21/2558360.html UTF8与GBK字符编码之间的相互转换 C++ UTF8编码转换 ...

  5. 【miscellaneous】【C/C++语言】UTF8与GBK字符编码之间的相互转换

    UTF8与GBK字符编码之间的相互转换 C++ UTF8编码转换 CChineseCode 一 预备知识 1,字符:字符是抽象的最小文本单位.它没有固定的形状(可能是一个字形),而且没有值." ...

  6. strconv:各种数据类型和字符串之间的相互转换

    介绍 strconv包实现了基本数据类型和其对应字符串之间的相互转换.主要有一下常用函数:Atoi,Itoa,Parse系列,Formart系列,Append系列 string和int之间的转换 这一 ...

  7. C# Enum Name String Description之间的相互转换

    最近工作中经常用到Enum中Value.String.Description之间的相互转换,特此总结一下. 1.首先定义Enum对象 public enum Weekday { [Descriptio ...

  8. 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换

    [源码下载] 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换 作者:webabcd 介绍速战速决 之 PHP ...

  9. json和string 之间的相互转换

    json和string 之间的相互转换 <script type="text/javascript"> //先认识一下js中json function showInfo ...

随机推荐

  1. angularjs项目中关于服务的应用

    /** *普通ajax请求公共服务 */ mainModule.factory('myService',function($http,$q){ var service = {}; var baseUr ...

  2. Android中Application全局方法(变量)的调用

    Application和Actovotu,Service一样是android框架的一个系统组件,当android程序启动时系统会创建一个 application对象,用来存储系统的一些信息.通常我们是 ...

  3. datazen 备份还原

    DataZen备份:   DataZen还原 第一步:用管理员进入dos,输入 net stop datazen 第二步:切换到datazen Core Service的安装目录cd c:\Progr ...

  4. struts2与spring整合问题,访问struts2链接时,spring会负责创建Action

    每次访问一次链接,spring会创建一个对象,并将链接所带的参数注入到Action的变量中(如何做到的呐) 因为: struts2的action每次访问都重新创建一个对象,那spring的ioc是怎么 ...

  5. Oracle11G安装

    1.安装Oracle 记住要设置好密码 不要忘了 解锁scott(注意一定要解锁)账户, 去掉前面的绿色小勾,输入密码.同样可以输入平常用的短小的密码,不必非得按oracle建议的8位以上大小写加数字 ...

  6. C#设置IP地址,启用禁用适配器

    界面效果图如下: 报表界面 说下关键代码 需要开启 Windows Management Instrumentation服务(默认已经开启),在程序中需要增加 Management引用. 主要有Net ...

  7. 8个不可不知的Mac OS X专用命令行工具(转)

    OS X的终端下通用很多Unix的工具和脚本.如果从Linux迁移到OS X会发现很多熟悉的命令和脚本工具,其实并没有任何区别. 但是OS X也提供了很多其他系统所没有的特别的命令行工具.我们推荐8个 ...

  8. adb server is out of date. killing... 解决方案

    忘了原文从哪来的了,过后查到补上链接 今天调试android的时候发现一个诡异的问题 C:\Users\xxxx>adb start-server   adb server is out of ...

  9. Android学习----五大布局

    1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...

  10. jquery图片轮播代码

    自己写的轮播代码 来张样式效果图 先贴HTML样式 <body> <div id = "wrap"> <div id="lunbo-img& ...