byte,bitmap,image互转
/// <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 = null;
using (MemoryStream ms= new MemoryStream())
{
using (Bitmap Bitmap = new Bitmap(Image))
{
Bitmap.Save(ms, imageFormat);
ms.Position = 0;
data = new byte[ms.Length];
ms.Read(data, 0, Convert.ToInt32(ms.Length));
ms.Flush();
}
}
return data;
}
/// <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;
}
}
//Image转换Bitmap
1. Bitmap img = new Bitmap(imgSelect.Image);
2. Bitmap bmp = (Bitmap)pictureBox1.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 ;
}
//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();
}
}
//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,bitmap,image互转的更多相关文章
- Bitmap byte[] InputStream Drawable 互转
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStrea ...
- java中byte和blob互转
1. btye[]转blob byte[] bs = ... Blob blob = conn.createBlob(); blob.setBytes(1, bs); ps.setBlob(2, bl ...
- C# byte[]与char[]、string与char[]、byte[] 与 string 互转
1. byte array -> char array Byte[] b=new byte[5]{0x01,0x02,0x03,0x04,0x05}; Char[] c=Encoding.AS ...
- Bitmap Byte[] 互转
严正声明:作者:psklf出处: http://www.cnblogs.com/psklf/p/5889978.html欢迎转载,但未经作者同意,必须保留此段声明:必须在文章中给出原文连接:否则必究法 ...
- 【转】Drawable /Bitmap、String/InputStream、Bitmap/byte[]
原文:http://wuxiaolong.me/2015/08/10/Drawable-to-Bitmap/ Drawable互转Bitmap Drawable转Bitmap 1234 Resourc ...
- Android Drawable、Bitmap、byte[]之间的转换
转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...
- Android中Bitmap,byte[],Drawable相互转化
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- 【Android】[转] Android中Bitmap,byte[],Drawable相互转化
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- C# Bitmap类型与Byte[]类型相互转化
Bitmap => byte[] Bitmap b = new Bitmap( "test.bmp "); MemoryStream ms = new Memory ...
随机推荐
- .net开发之我见,or实现 最简 优化法。knock out type convert 与我之简化orm的实现原理及实现细则,最简化开发法
现在的.net or构架,大家认同的各种大大小小,ef,subsonic,nhibernate,甚至小一些的petapoco这种,但用过的人我想他们考虑的是比较多. 小一些的Petapoco也有几千行 ...
- find 命令使用总结
参考:http://os.51cto.com/art/200908/141119.htm 1.find命令的一般形式 find pathname -options [-print -exec -ok ...
- cluster集群
http://zwfang09.blog.sohu.com/entry/ Cluster 集群 ,群集 --- 负载均衡 LB ,load-balance --- 高可用集群 HA ,High Ava ...
- paper 56 :机器学习中的算法:决策树模型组合之随机森林(Random Forest)
周五的组会如约而至,讨论了一个比较感兴趣的话题,就是使用SVM和随机森林来训练图像,这样的目的就是 在图像特征之间建立内在的联系,这个model的训练,着实需要好好的研究一下,下面是我们需要准备的入门 ...
- EBS常用小常识(转)
值集: 1.编辑信息:取上一个值集所选的数据.(值集关联) WHERE BANK_ACCOUNT_ID = :$FLEX$.CE_BANK_ACCOUNT_NUM_NAME ORDER BY STAT ...
- 夺命雷公狗—angularjs—2—模拟表单验证
这里我们就来借助妹子ui来搭建下模版,废话不多说,代码如下图所示: <!doctype html> <html lang="en"> <head> ...
- Verilog中的specify block和timing check
在ASIC设计中,有两种HDL construct来描述delay信息: 1)Distributed delays:通过specify event经过gates和nets的time,来描述delay; ...
- Android2.2快速入门 zz
http://www.cnblogs.com/over140/archive/2010/09/27/1836567.html 前言 这是前段时间用于公司Android入门培训的资料,学习Android ...
- 集成Spring事物管理
什么是事物 事物是访问数据库的一个操作序列,数据库应用系统通过事物集来完成对数据库的存取.事物的正确执行使得数据库从一种状态转换为另一种状态. 事物必须服从ISO/IEC所制定的ACID原则.ACID ...
- delphi 与 C++的基本语法区别
[1]“=”符号 (1)“=”作为比较符.但是,当定义const常量时,“=”又表示赋值符号.而“:=”作为赋值符号. (2)“=”只表示赋值符号 [2]结构体 (1)record 作为结构体 (2) ...