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. Retrofit2 简介 语法 案例

    简介 官网:http://square.github.io/retrofit/ GitHub:https://github.com/square/retrofit/ compile 'com.squa ...

  2. html02表格的使用

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. php 写model层

    <?php /** * @author Administrator * */ class User { private $id; private $admin; private $paw; pr ...

  4. IIS支持APK/ISO文件下载的方法

    默认把安卓手机应用或游戏的apk格式文件上传到服务器空间是不能直接下载的,这是因为IIS的默认MIME类型中没有.apk文件,所以无法下载.@VCOO 既然.apk无法下载是因为没有MIME,那么添加 ...

  5. 【javascript模式】Chapter2: 基本 技巧

    1 尽量少用全局变量,最好一个应用程式只有一个全局变量  隐含全局变量(不使用var声明)与明确定义的全局变量区别:  (1)使用var创建的全局变量(在函数外部声明)不能用delete删除  (2) ...

  6. CSS 布局Float 【3】

    float 属性定义元素在哪个方向浮动. 浮动元素会生成一个块级框,而不论它本身是何种元素. 如果浮动非替换元素,则要指定一个明确的宽度:否则,它们会尽可能地窄. 注释:假如在一行之上只有极少的空间可 ...

  7. java_reflect_03

    关于反射在annotation中的使用,这也是本次我个人学习反射的主要目的 关于什么是annotation后续我也会整理一下,现在只大致介绍一下 一,Annotation(注解)简介: 注解大家印象最 ...

  8. input border IE6 bug

    border:none;与border:0;的区别体现有两点:一是理论上的性能差异二是浏览器兼容性的差异. 1.性能差异[border:0;]把border设为“0”像素虽然在页面上看不见,但按bor ...

  9. How to check a not defined variable in javascript

    javascript里怎么检查一个未定义的变量? in JavaScript null is an object. There's another value for things that don' ...

  10. TCP/IP-UDP

    We read the world wrong but say that it deceives us. "我们看错了世界,却说世界欺骗了我们" 参考资料:TCP/IP入门经典 ( ...