blob-照片转换与展示
File转java.sql.Blob(照片)Struts2
public Blob photos(File zp) {
Blob photo=null;
try {
FileInputStream fis = new FileInputStream(zp);
BufferedInputStream bis = new BufferedInputStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = bis.read();
while (c != -1) {
baos.write(c);
c = bis.read();
}
bis.close();
byte[] rtn= baos.toByteArray();
InputStream input=new ByteArrayInputStream(rtn);
photo = Hibernate.createBlob(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return photo;
}
FormFile转java.sql.Blob(照片)Struts1
public Blob photos(FormFile zp) {
Blob photo = null;
if(zp !=null)
{
try {
InputStream input = zp.getInputStream();
photo = Hibernate.createBlob(input);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return photo;
}
获取照片struts
public void getZp(ActionMapping mapping, ActionForm actionform, HttpServletRequest request, HttpServletResponse response) {
Blob photo = "从数据库中返回的照片字段";
OutputStream out = null;
response.setContentType("image/jpeg");
InputStream is = null;
if(photo != null || !"".equals(photo))
{
try {
is = photo.getBinaryStream();
byte[] buffer = new byte[1024];
out = response.getOutputStream();
int length = 0;
while((length = is.read(buffer)) != -1){
out.write(buffer,0,length);
}
} catch (Exception e) {
log.error("用户没有录入照片"+e);
}finally
{
try {
out.flush();
out.close();
} catch (IOException e) {
log.error("流没有关闭"+e);
}
}
}
}
jsp页面:
<c:if test="${not empty photo}"><!-- 请求获取照片 -->
<img src="${Context}/admin/yzxx.do?method=getZp&id=${yzxx.id}" width="100" height="100" id="imageId"/>
</c:if>
<c:if test="${empty photo}"><!-- 照片为空时显示系统照片 -->
<img src="${Context}/images/default_head.jpg" width="100" height="100" id="imageId"/>
</c:if>
blob-照片转换与展示的更多相关文章
- 使用Canvas把照片转换成素描画
原文:http://www.alloyteam.com/2012/07/convert-picture-to-sketch-by-canvas/ 腾讯的alloy team写的一个素描效果,挺不错的. ...
- Joyoshare HEIC Converter for Mac将HEIC照片转换成其他格式的方法
如何把HEIC格式的照片转换成其JPEG,PNG,GIF他格式呢?使用Joyoshare HEIC Converter for Mac破解版就可以,Joyoshare HEIC Converter是可 ...
- vue 项目文件流数据格式转blob图片预览展示
为了图片安全性,有时候上传图片后后台不会直接返回图片地址,会返回文件流的数据格式,这种格式需要处理下才能展示在页面上 // 使用axios请求上传接口 axios({ method: 'get', ...
- python 实用技巧:几十行代码将照片转换成素描图、随后打包成可执行文件(源码分享)
效果展示 原始效果图 素描效果图 相关依赖包 # 超美观的打印库 from pprint import pprint # 图像处理库 from PIL import Image # 科学计算库 imp ...
- 如何将你拍摄的照片转换成全景图及六面体(PTGui)
在完成全景照片的拍摄之后,接下来,我们需要的是进行全景图的拼接.全景图片分为两种类型1.立方体全景图(6面体)制作全景时通常使用该种格式 如下图 2.球形图(2:1的单张全景图片)2:1全景图宽高比例 ...
- base64和Blob互相转换
1.base64转blob(二进制数据) /** * 将以base64的图片url数据转换为Blob * @param urlData 用url方式表示的base64图片数据 */ functio ...
- Base64转换二进制文件对象 Blob/Base64转换 File 对象
function convertBase64UrlToBlob(urlData) { var arr = dataurl.split(','),//去掉url的头,并转换为byte type = ar ...
- HTML5 Blob与ArrayBuffer、TypeArray和字符串String之间转换
1.将String字符串转换成Blob对象 //将字符串 转换成 Blob 对象 var blob = new Blob(["Hello World!"], { type: 'te ...
- "ORA-01460: 转换请求无法实现或不合理"及C#操作Blob总结
class BlobDemo { private static readonly string ConnectionString = "Data Source=Tcco;User ID=sc ...
随机推荐
- gdb x查看二进制
参考 http://blog.csdn.net/allenlinrui/article/details/5964046 (gdb) disassemble main Dump of assembler ...
- Flume的可管理性
Flume的可管理性 所有agent和Collector由master统一管理,这使得系统便于维护. 多master情况,Flume利用 ZooKeeper和gossip,保证动态配置数据的一致性. ...
- golang 部分理解:关于channel 和 goroutine 例子
部分理解:关于channel 和 goroutine 例子package main import "strconv" import "fmt" func mai ...
- Codefroces 760 B. Frodo and pillows
B. Frodo and pillows time limit per test 1 second memory limit per test 256 megabytes input standard ...
- ACM 中JAVA的应用
原文地址:http://www.cppblog.com/vontroy/archive/2010/05/24/116233.html 先说一下Java对于ACM的一些优点吧: (1) 对于熟悉C/C+ ...
- BZOJ1212: [HNOI2004]L语言(Trie图+DP)
Description 标点符号的出现晚于文字的出现,所以以前的语言都是没有标点的.现在你要处理的就是一段没有标点的文章. 一段文章T是由若干小写字母构成.一个单词W也是由若干小写字母构成.一个字典D ...
- iptables转发安卓手机热点的数据到指定的端口
iptables转发安卓手机热点的数据到指定的端口 手机安装了VPN,可以上GOOGLE的那种.然后我打开手机的热点,连上笔记本,想让本本上个google 没想到被GFW挡住了.看了一下手机的网络工作 ...
- 数据集 —— ground truth 数据集
1. matlab 自带含 ground truth 数据集 %% 加载停车标志数据到内存: data = load('stopSignsAndCars.mat', 'stopSignsAndCars ...
- @Import注解
转自:https://blog.csdn.net/heyutao007/article/details/74994161 @Import注解就是之前xml配置中的import标签,可以用于依赖第三方包 ...
- 自定义HTML标签属性
为HTML元素添加一自定义的属性非常方便,只须将其加到尖括号中即可,与内置属性地位相等. 如我们要为TextBox元素添加属性idvalue: <input type="text&qu ...