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. 超级钢琴 2010年NOI

    /* 自己yy的奇葩做法居然A了23333 不过空间好像很大 时间好像略慢..... 毕竟不是正解 前缀维护sum值 枚举区间起点 然后终点的坐标可以确定在一个范围 可持久化线段树查询区间第1大 然后 ...

  2. PHP 注意问题

    一.表单  1,上传文件的表单使用post方式:还要加上enctype='multipart/form-data'.     2,一般要加上隐藏域:<input type=hidden name ...

  3. C#异常处理表、类、SQL

    表SQL /****** Object: Table [dbo].[IError] Script Date: 09/05/2012 17:00:41 ******/ SET ANSI_NULLS ON ...

  4. oracle查询表信息(索引,外键,列等)

    oracle中查询表的信息,包括表名,字段名,字段类型,主键,外键唯一性约束信息,索引信息查询SQL如下,希望对大家有所帮助:1.查询出所有的用户表 select * from user_tables ...

  5. JavaScript--对象+函数

    1. 复杂数据类型 Object ECMAScript中的对象其实就是一组数据(属性)和功能(方法)的集合.    1) 创建Object实例:   1.使用构造函数创建,new Object()   ...

  6. ReactNative for Android入坑(一)

    最近找工作发现有些公司要求会ReactNative,决定入坑. 搭建环境:官网详细的教程附链接. 坑一:FQ,建议整个搭建过程中FQ.(FQ链接,注册有200M试用流量,环境搭建够了)第一步:安装Ch ...

  7. 数据类型的转换String

    x.toString(): 无法转换null和undefined 不过String()却是万能的,其中的原理如下 function String(x){ if(x===undefined){ retu ...

  8. 模仿qq音乐播放字母效果

    html <div class="cont"> <ul class="cont_ul" id="cont_ul"> ...

  9. 在VMware安装Centos再安装Oracle数据库(个人学习使用)

    打开VMware 选择稍后安装 自定义安装 小生安装的是64位的Centos 给虚拟机设置名称和安装位置 设置虚拟机打处理器并分配内存(oracle12G我建议内存为2G以上) 网络类型选择仅主机模式 ...

  10. Adb shell 常用命令

    1. 查看IP adb shell netcfg 2. 查看挂载设备 adb devices 3. 将本地端口转发至手机端口 adb forward tcp: tcp: // PC上所有6100端口通 ...