Image 和byte[]之间的转换
1.Image 转 byte[]
public byte[] GetByteByImage(Image image)
{
byte[] bt = null;
try
{
if (!image.Equals(null))
{
MemoryStream ms = new MemoryStream();
Bitmap bmp = new Bitmap(image);
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bt = new byte[ms.Length];
ms.Position = 0;
ms.Read(bt, 0, Convert.ToInt32(bt.Length));
bmp.Dispose();
ms.Dispose();
ms.Close();
}
}
catch (Exception ex)
{
throw ex;
}
return bt;
}
2.byte[] 转Image
public Image GetImageByByte(byte[] imageBytes)
{
Image image = null;
try
{
MemoryStream ms = new MemoryStream(imageBytes);
ms.Write(imageBytes, 0, imageBytes.Length);
image = Image.FromStream(ms, true);
ms.Dispose();
ms.Close();
}
catch (Exception ex)
{
throw ex;
}
return image;
}
Image 和byte[]之间的转换的更多相关文章
- C# Stream 和 byte[] 之间的转换
一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...
- Stream 和 byte[] 之间的转换
Stream 和 byte[] 之间的转换 一. 二进制转换成图片 ? 1 2 3 4 5 MemoryStream ms = new MemoryStream(bytes); ms.Position ...
- C# Stream 和 byte[] 之间的转换(文件流的应用)
一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...
- C#实现Stream与byte[]之间的转换实例教程
一.二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream(m ...
- 将String转化成Stream,将Stream转换成String, C# Stream 和 byte[] 之间的转换(文件流的应用)
static void Main( string[] args ) { string str = "Testing 1-2-3"; //convert string 2 strea ...
- C#下载文件,Stream 和 byte[] 之间的转换
stream byte 等各类转换 http://www.cnblogs.com/warioland/archive/2012/03/06/2381355.html using (System.Net ...
- Drawable、Bitmap、byte[]之间的转换
android在处理一写图片资源的时候,会进行一些类型的转换: 1 Drawable → Bitmap 的简单方法 ((BitmapDrawable)res.getDrawable(R.drawabl ...
- C#--整型与字节数组byte[]之间的转换
using System; int i = 123;byte [] intBuff = BitConverter.GetBytes(i); // 将 int 转换成字节数组lob.Write ...
- 字符串与byte[]之间的转换
一. 编码 同一个字符在不同的编码下会被编成不同长度的编码,比如: ACSII,每个字符对应一个字节,实际上只使用了7位,从00h-7Fh.只能表达128个字符. GB2312,中文的一种编码,每个 ...
- Android Drawable、Bitmap、byte[]之间的转换
转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...
随机推荐
- Ubuntu 16.04 natural scrolling
http://ubuntuhandbook.org/index.php/2016/05/install-ubuntu-tweak-in-ubuntu-16-04/ download ubuntu-tw ...
- GCC参数详解 二
1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...
- codis须知
codis是豌豆荚team出的一个redis集群,和官方的集群区别的地方在于 基于proxy,官方是基于gossip codis所有的读写都通过proxy,对于前端业务是透明的 官方的是读写发现在某个 ...
- log4net 极简配置
log4net的配置详解 分类: C#2013-10-01 22:45 5335人阅读 评论(4) 收藏 举报 log4net日志框架 前言:没买到1号回家的票,所以在祖国64岁生日之 ...
- HDU 4004 The Frog's Games(二分+小思维+用到了lower_bound)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- charles 小米手机安装Charles证书
1.手机Wi-Fi设置手动代理,添加IP和端口号 此处是:192.168.63.143:8888, 2.保存证书,PC端访问 chls.pro/ssl 下载pem证书,发送到手机 adb push c ...
- struts1的一个简单登陆功能
Login.jsp: <form action="<%= request.getContextPath() %>/login.do" method="p ...
- JQuery的筛选方法
前面咱们学习到了jquery的选择器的筛选用法,那么咱们接下来学习一下jquery的常用筛选方法,一张图搞定一切.
- OpenMP 旅行商问题,静态调度
▶ <并行程序设计导论>第六章中讨论了旅行商,分别使用了 MPI,Pthreads,OpenMP 来进行实现,这里是 OpenMP 的代码,分为静态调度(每个线程分分配等量的搜索人物)和动 ...
- Docker compose自动化部署
安装 https://docs.docker.com/compose/install/#install-compose