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. 分页技术之GridView控件

    GridView控件实现分页技术 第一步:设置GridView控件的属性,跟分页相关的属性设置如下: AllowPaging="true":允许分页, PageSize=" ...

  2. POJ 2438 (哈密顿回路)

    分析: 2*n个小朋友,每个最多有n-1个"敌人",显然是存在哈密顿回路的. 预处理边,然后找哈密顿回路. code #include <iostream> #incl ...

  3. 【USACO 3.3.2】商品购物

    [描述] 在商店中,每一种商品都有一个价格(用整数表示).例如,一朵花的价格是 2 zorkmids (z),而一个花瓶的价格是 5z .为了吸引更多的顾客,商店举行了促销活动. 促销活动把一个或多个 ...

  4. jQuery 如何创建基本插件(翻译)

    有时候,你希望有一块功能在整个代码当中都可以使用.例如,你可能想要有一个单一的方法可以在jQuery选择器上进行调用,用于处理该选择器上的一系列操作.又或许你编写了一个十分有用的工具函数,并希望能够简 ...

  5. JQUERY1.9学习笔记 之基本过滤器(十) 非选择器

    非选择器jQuery( ":not(selector)" ) 例:找出所有input标签为非"checked"的,并且高亮其邻居元素span. <!DOC ...

  6. mysql的sql优化案例

    前言 mysql的sql优化器比较弱,选择执行计划貌似很随机. 案例 一.表结构说明mysql> show create table table_order\G***************** ...

  7. 总结:ARM逻辑和高级C(朱老师物联网学习)

    开始学习朱老师物联网的视频是国庆节的那几天开始的,刚刚开始的时候是想自己在网上找一些嵌入式方面的视频资料,也找了很多的资料臂如“国嵌视频”“达内的视频”,之后也化了十几块钱在淘宝上面买了几十个G的视频 ...

  8. POJ1700:Crossing River(过河问题)

    POJ1700 题目链接:http://poj.org/problem?id=1700 Time Limit:1000MS     Memory Limit:10000KB     64bit IO ...

  9. java的类加载机制

    1.概述 Class文件由类装载器装载后,在JVM中将形成一份描述Class结构的元信息对象,通过该元信息对象可以获知Class的结构信息:如构造函数,属性和方法等,Java允许用户借由这个Class ...

  10. 14.4.5 System Tablespace 系统表空间

    14.4.5 System Tablespace 系统表空间 InnoDB 系统表空间包含InnoDB 数据目录(元数据 用于InnoDB相关对象)和是存储区域用于doublewrite buffer ...