社区
VB基础类
帖子详情
VB byte[] 保存为jpg图片或转换stream
daiyong_88
2010-12-29 07:11:42
如题
...全文
200
1
打赏
收藏
VB byte[] 保存为jpg图片或转换stream
如题
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
贝隆
2010-12-29
打赏
举报
回复
http://download.csdn.net/source/1483930
如何将
图片
转换
成二进制存储
图片
的常见存储与读取凡是有以下几种: 存储
图片
:以二进制的形式存储
图片
时,要把数据库中的字段设置为Image数据类型(SQL Server),存储的数据是
Byte
[]. 1.参数是
图片
路径:返回
Byte
[]类型: public
byte
[] GetPictureData(string imagepath) { /**/////根据
图片
文件的路径使用文件流打开,并
保存
为
byte
[] File
Stream
fs = new File
Stream
(imagepath, FileMode.Open);//可以是其他重载方法
byte
[] byData = new
byte
[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); return byData; }2.参数类型是Image对象,返回
Byte
[]类型: public
byte
[] PhotoImageInsert(System.Drawing.Image imgPhoto) { //将Image
转换
成流数据,并
保存
为
byte
[] Memory
Stream
m
stream
= new Memory
Stream
(); imgPhoto.Save(m
stream
, System.Drawing.Imaging.ImageFormat.Bmp);
byte
[] byData = new
Byte
[m
stream
.Length]; m
stream
.Position = 0; m
stream
.Read(byData, 0, byData.Length); m
stream
.Close(); return byData; }好了,这样通过上面的方法就可以把
图片
转换
成
Byte
[]对象,然后就把这个对象
保存
到数据库中去就实现了把
图片
的二进制格式
保存
到数据库中去了。下面我就谈谈如何把数据库中的
图片
读取出来,实际上这是一个相反的过程。 读取
图片
:把相应的字段
转换
成
Byte
[]即:
Byte
[] bt=(
Byte
[])XXXX 1.参数是
Byte
[]类型,返回值是Image对象: public System.Drawing.Image ReturnPhoto(
byte
[]
stream
Byte
) { System.IO.Memory
Stream
ms = new System.IO.Memory
Stream
(
stream
Byte
); System.Drawing.Image img = System.Drawing.Image.From
Stream
(ms); return img; }2.参数是
Byte
[] 类型,没有返回值,这是针对asp.net中把
图片
从输出到网页上(Response.BinaryWrite) public void WritePhoto(
byte
[]
stream
Byte
) { // Response.ContentType 的默认值为默认值为“text/html” Response.ContentType = "image/GIF"; //
图片
输出的类型有: image/GIF image/JPEG Response.BinaryWrite(
stream
Byte
); }补充: 针对Response.ContentType的值,除了针对
图片
的类型外,还有其他的类型: Response.ContentType = "application/msword"; Response.ContentType = "application/x-shockwave-flash"; Response.ContentType = "application/vnd.ms-excel";另外可以针对不同的格式,用不同的输出类型以适合不同的类型: switch (dataread("document_type")) { case "doc": Response.ContentType = "application/msword"; case "swf": Response.ContentType = "application/x-shockwave-flash"; case "xls": Response.ContentType = "application/vnd.ms-excel"; case "gif": Response.ContentType = "image/gif"; case "
Jpg
": Response.ContentType = "image/jpeg"; }
VB
6 在内存中生成bitmap图像,并将其
保存
为
byte
()数组
在
VB
6内存中创建bitmap图像,并将其
保存
为
byte
()数组 在项目中添加一个模块,用于封装GDIPlus函数 从内存中创建相应的信息 '全局声明 Dim token As Long Dim graphics As Long Dim img As Long, W As Long, H As Long Dim pen As Long Dim brush As ...
[
VB
]GDI+ I
Stream
、StdPicture、
Byte
() 互转
很多年前就想做一个远程控制的软件,只是一直以来
图片
的压缩速度总是提升不上去,而我也参考过很多网上的关于
图片
压缩的例子,比如zyl910的GIF_LZW压缩方法,Huffman压缩方法,以至到GDI+的直接生成
JPG
、PNG的方法(这种方法无论从压缩率和速度上都是最佳的,可惜这种方法网上一直没找到直接
保存
为
Byte
()的例子,见得最多的例子就是用GdipSaveImageToFile
保存
到磁盘,然后
.net 中
图片
和
byte
的相互
转换
1.
byte
转Image public static Image
Byte
sToImage(
byte
[] buffer) { Memory
Stream
ms = new Memory
Stream
(buffer); Image image = System.Drawing.Image.From
Stream
(ms); return image; } 2.Image转
byte
Bitmap bitma...
byte
数组与Image的相互
转换
功能需求: 1、把一张
图片
(png bmp jpeg bmp gif)
转换
为
byte
数组存放到数据库。 2、把从数据库读取的
byte
数组
转换
为Image对象,赋值给相应的控件显示。 3、从
图片
byte
数组得到对应
图片
的格式,生成一张
图片
保存
到磁盘上。 这里的Image是System.Drawing.Image。 //Get an image
VB基础类
7,765
社区成员
197,605
社区内容
发帖
与我相关
我的任务
VB基础类
VB 基础类
复制链接
扫一扫
分享
社区描述
VB 基础类
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章