//将image转化为二进制
public static byte[] GetByteImage(Image img)
{
byte[] bt = null;
if (!img.Equals(null))
{
using (MemoryStream mostream = new MemoryStream())
{
Bitmap bmp = new Bitmap(img);
bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//将图像以指定的格式存入缓存内存流 bt = new byte[mostream.Length];
mostream.Position = ;//设置留的初始位置
mostream.Read(bt, , Convert.ToInt32(bt.Length));
}
}
return bt;
} /// <summary>
/// 将实际位置中的照片转化为byte[]类型写入数据库中
/// </summary>
/// <param name="strFile">string图片地址</param>
/// <returns>byte[]</returns>
public static byte[] GetBytesByImagePath(string strFile)
{
byte[] photo_byte = null;
using (FileStream fs =
new FileStream(strFile, FileMode.Open, FileAccess.Read))
{
using (BinaryReader br = new BinaryReader(fs))
{
photo_byte = br.ReadBytes((int)fs.Length);
}
}
return photo_byte;
} /// <summary>
/// 读取byte[]并转化为图片
/// </summary>
/// <param name="bytes">byte[]</param>
/// <returns>Image</returns>
public static Image GetImageByBytes(byte[] bytes)
{
Image photo = null;
using (MemoryStream ms = new MemoryStream(bytes))
{
ms.Write(bytes, , bytes.Length);
photo = Image.FromStream(ms, true);
}
return photo;
}

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. PHP 加密的几种方式

    在使用PHP开发Web应用的中,很多的应用都会要求用户注册,而注册的时候就需要我们对用户的信息进行处理了,最常见的莫过于就是邮箱和密码了,本文意在讨论对密码的处理:也就是对密码的加密处理. MD5 相 ...

  2. flex mx组件和s组件的字体兼容性不一致

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  3. (个人)读取A.CSV修改它的某列,写入B.CSV

    #!/usr/bin/perl -wuse strict;use warnings;use Tie::File; open(IN_FILE,"<E:/Hzj_works/test1.c ...

  4. [转]System.Reflection.AssemblySignatureKeyAttribute

    转自:http://www.cnblogs.com/ego/p/3321122.html 错误: Could not load type 'System.Reflection.AssemblySign ...

  5. oracle 导出表结构和数据,使用plsql

    比如说需要把A数据库里面的数据,导入到B数据库 准备工作:在B数据库中创建B数据库同名的的用户名和表空间,注意大小写必须一样. 1,导出表结构.A数据库里点击工具栏里的tools--Export Us ...

  6. Codeforces 735D:Taxes(哥德巴赫猜想)

    http://codeforces.com/problemset/problem/735/D 题意:给出一个n,这个n可以分解成 n = n1 + n2 + -- + nk,其中k可以取任意数.要使得 ...

  7. SQLServer学习笔记<>日期和时间数据的处理(cast转化格式、日期截取、日期的加减)和 case表达式

    日期和时间数据的处理. (1)字符串日期 ‘20080301’,这一串为字符串日期,但必须保证为四位的年份,两位的月份,两位的日期.例如,查询订单表日期大于‘20080301’.可以这样写: 1 se ...

  8. [HTML]js实现页面跳转,页面A跳到另一个页面B.以及页面传值(中文)

    要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码 JS跳转大概有以下几种方式: 第一种:(跳转到b.html)<script language="javascri ...

  9. ACM题目————Anagram

    Description You are to write a program that has to generate all possible words from a given set of l ...

  10. [转]Mac OS X framework 解析

    转载地址:http://hi.baidu.com/yonderbyron/item/9838b73472152e009cc65ec8 Mac OS X framework 解析 1.framework ...