//图片的"读"操作
//①参数是图片路径:返回Byte[]类型:
//参数是图片的路径
public byte[] GetPictureData(string imagePath){
FileStream fs=new FileStream(imagePath,FileMode.Open);
byte[] byteData=new byte[fs.Length];
fs.Read(byteData,,byteData.Length);
fs.Close();
return byteData();
}
//②参数类型是Image对象,返回Byte[]类型
//将Image转换成流数据,并保存为byte[] 
public byte[] PhotoImageInsert(System.Drawing.Image imgPhoto)
{
MemoryStream mstream = new MemoryStream();
imgPhoto.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] byData = new Byte[mstream.Length];
mstream.Position = ;
mstream.Read(byData, , byData.Length); mstream.Close();
return byData;
}
//图片的“写”操作
//①参数是Byte[]类型,返回值是Image对象
public System.Drawing.Image ReturnPhoto(byte[] streamByte)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
return img;
}
//②参数是Byte[] 类型,没有返回值(ASP.NET输出图片)
public void WritePhoto(byte[] streamByte)
{
// Response.ContentType 的默认值为默认值为“text/html”
Response.ContentType = "image/GIF";
//图片输出的类型有: image/GIF image/JPEG
Response.BinaryWrite(streamByte);
}

图片和byte[]的互相转换的更多相关文章

  1. 图片和base64编码字符串 互相转换,图片和byte数组互相转换

    图片和base64编码字符串 互相转换 import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import java.io.*; ...

  2. Java 图片与byte数组互相转换

    //图片到byte数组 public byte[] image2byte(String path){ byte[] data = null; FileImageInputStream input = ...

  3. java 实现 图片与byte 数组互相转换

    package webgate; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import ja ...

  4. 图片转为byte[]、String、图片之间的转换

    package com.horizon.action; import java.io.ByteArrayOutputStream; import java.io.File; import java.i ...

  5. C# Stream 和 byte[] 之间的转换

    一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...

  6. Stream 和 byte[] 之间的转换

    Stream 和 byte[] 之间的转换 一. 二进制转换成图片 ? 1 2 3 4 5 MemoryStream ms = new MemoryStream(bytes); ms.Position ...

  7. C# Stream 和 byte[] 之间的转换(文件流的应用)

    一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream( ...

  8. 在imge控件中直接显示图片(图片是byte[]格式)

    在工作过程中遇到了这个问题,在网上查了一些资料,结合自己的解决方法及解决过程总结了下,方面以后查阅.如果能帮到同样遇到这个问题的你,将非常高兴哦~_~ 由于asp.net中的Image控件是在Syst ...

  9. C#实现Stream与byte[]之间的转换实例教程

    一.二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream(m ...

随机推荐

  1. 关于ECharts内存泄漏问题

    最近使用websocket加ECharts做了一个实时监控的功能,发现了一个比较严重的问题,就是浏览器运行一段时间就会非常卡,之前在ECharts官网运行官方实例“动态数据 + 时间坐标轴”时,也遇到 ...

  2. flask的自定义过滤器

    过滤器的本质是函数.当模板内置的过滤器不能满足需求,可以自定义过滤器.自定义过滤器有两种实现方式: 一种是通过Flask应用对象的 add_template_filter 方法 通过装饰器来实现自定义 ...

  3. ecshop漏洞修复 以及如何加固ecshop网站安全?

    由于8月份的ECSHOP通杀漏洞被国内安全厂商爆出后,众多使用ecshop程序源码的用户大面积的受到了网站被篡改,最明显的就是外贸站点被跳转到一些仿冒的网站上去,导致在谷歌的用户订单量迅速下降,从百度 ...

  4. centos7上部署新版 jumpserver 跳板机服务

    CentOS 7 建议在一个纯净的 centos7上进行下面的安装部署 关闭 selinux 和防火墙 [root@jumpserver ~]# setenforce 0 [root@jumpserv ...

  5. error:control reaches end of non-void function [-Werror=return-type]

    在做LeetCode上的题目时,出现了这个错误, 原代码如下: class Solution { public: vector<int> twoSum(vector<int>& ...

  6. Redis的自从复制(Master/Slave)

    一.是什么? 行话:也就是我们所说的主从复制,主机数据更新后根据配置和策略,自动同步到备机的master/slaver机制,Master以写为主,Slave以读为主 二.能干嘛? 1.读写分离 2.容 ...

  7. go执行外部应用

    go执行外部应用 最近想将原来用asp.net mvc写的一个公司内部网站改用beego来写,但发现其中有一个功能是,能将加密的sqlite文件进行解密,因为这个解密是不能公开的,但有些同事需要查看这 ...

  8. 20145202马超《JAVA》预备作业3

    虚拟机的安装[http://www.cnblogs.com/tuolemi/p/5861062.html] Linux命令[http://www.cnblogs.com/tuolemi/p/58781 ...

  9. 3,jieba gensim 最好别分家之最简单的相似度实现

    简单的问答已经实现了,那么问题也跟着出现了,我不能确定问题一定是"你叫什么名字",也有可能是"你是谁","你叫啥"之类的,这就引出了人工智能 ...

  10. Python字符串处理:过滤字符串中的英文与符号,保留汉字

    使用Python 的re模块,re模块提供了re.sub用于替换字符串中的匹配项. re.sub(pattern, repl, string, count=0) 参数说明: pattern:正则重的模 ...