grails从数据库读取blob显示图片
来源:互联网 发布:海康网络视频监控方案 编辑:程序博客网 时间:2024/05/27 20:59
前台:
<tr class="t s">
<td class="l" width="120" style="color:#133A7B">图片:</td>
</tr>
<tr>
<td valign="top" class="name" style="font:12px;width:400px;height:400px;" >
<image src="/foi/obstacleReport/image?id=1" onload="FixedImage(this)"/>
</td>
</tr>
后台:
def image = {
if(params.id!=null){
Connection conn = SqlCon.getCon();
byte[] description = "";
def query ="""select photo from photo_list where id = """+params.id+""" and record_state=0 """;
def pstmt = conn.prepareStatement(query);
ResultSet result = pstmt.executeQuery();
StringBuffer myStringBuffer = new StringBuffer();
if (result.next()) {
java.sql.Blob blob = result.getBlob("photo");
InputStream inStream = blob.getBinaryStream();
long nLen = blob.length();
int nSize = (int) nLen;
description = new byte[nSize];
inStream.read(description);
inStream.close();
description = ChangeImgSize(description, 200, 200);
if(description!=null){
OutputStream op = response.getOutputStream();
op.write(description, 0, description.length);
op.close();
op = null;
}
response.flushBuffer();
}
result.close();
pstmt.close();
conn.close();
}
}
private byte[] ChangeImgSize(byte[] data, int nw, int nh){
byte[] newdata = null;
try{
BufferedImage bis = ImageIO.read(new ByteArrayInputStream(data));
if(bis!=null){
int w = bis.getWidth();
int h = bis.getHeight();
double sx = (double) nw / w;
double sy = (double) nh / h;
AffineTransform transform = new AffineTransform();
transform.setToScale(sx, sy);
//AffineTransformOp ato = new AffineTransformOp(transform, null);
//原始颜色
//BufferedImage bid = new BufferedImage(nw, nh, BufferedImage.TYPE_3BYTE_BGR);
//ato.filter(bis, bid);
//转换成byte字节
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bis, "jpeg", baos);
newdata = baos.toByteArray();
}
}catch(IOException e){
e.printStackTrace();
}
return newdata;
}
- grails从数据库读取blob显示图片
- 从数据库中读取Blob对象图片并显示
- 从数据库中读取Blob对象图片并显示
- 从数据库中读取Blob对象图片并显示
- Java从数据库中读取Blob对象图片并显示
- Java从Oracle读取Blob显示图片在页面
- 从数据库中读取blob字段并生成图片文件
- hibernate从sqlserver数据库中读取图片 Image (Blob)
- NODEjs 从数据库读取blob格式存储的图片
- 从Oracle中数据库中读取以Blob类型存储的图片显示在jsp页面中
- PowerBuilder从数据库读取并显示图片。
- Jsp从数据库读取并显示图片
- 从oracle中读取blob图片资源
- 数据库存储BloB格式图片,并从数据库中取出显示到页面中
- 救命呀!关于从数据库读取Word文档(BLOB)在JSP页面显示
- JSP读取Oracle数据库里的图片Blob字段并显示在页面上
- 从数据库读取图片
- 从数据库读取图片
- 创建和配置新的文档集内容类型
- 文件操作。简单的压缩、解压缩等
- bash参考手册之三(基本的Shell特性)续五
- 服务器更换硬盘后Oracle不能连接问题的解决
- struts1.2原理
- grails从数据库读取blob显示图片
- Android - ExpandableListView的group里添加button后不能展开的解决方法
- Spring的ID增长器使用示例(MySql数据库)
- xsd-3.2配置
- 创建守护进程(Daemon)
- WTF Desktop Environments: GNOME, KDE, and More Explained
- lucene3.5报错org.apache.lucene.queryParser.ParseException
- 如何更改UIPickerView的高度
- Unity3d之Quaternion 学习与应用