六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 86|回复: 0

jsp处理图片

[复制链接]

升级  20%

2

主题

2

主题

2

主题

童生

Rank: 1

积分
10
 楼主| 发表于 2013-2-6 09:49:27 | 显示全部楼层 |阅读模式
1、 简单控制图片width,height的例子
<script language="javascript" type="text/javascript">
function forBig(id)
{
var node = document.getElementById(id);
var width = node.getAttribute("width");
var height = node.getAttribute("height");
node.setAttribute("width",width+20);
node.setAttribute("height",height+20);
}
function forSmall(id)
{
var node = document.getElementById(id);
var width = node.getAttribute("width");
var height = node.getAttribute("height");
node.setAttribute("width",width-10);
node.setAttribute("height",height-10);
}
</script>



简单控制图片width,height的例子//图片路径楼主把握一下
<script language="javascript" type="text/javascript">
function enlarge(id)
{
var node = document.getElementById(id);
var width = node.getAttribute("width");
var height = node.getAttribute("height");
node.setAttribute("width",width+20);
node.setAttribute("height",height+20);
}
function shrink(id)
{
var node = document.getElementById(id);
var width = node.getAttribute("width");
var height = node.getAttribute("height");
node.setAttribute("width",width-10);
node.setAttribute("height",height-10);
}
</script>
</HEAD>
-----------------------
<BODY>
<button >放大</button><button >缩小</button><br/><br/>
<img id="image" src="./image/image1.gif"><!--//换成你的图片路径-->
</BODY>
</HTML>


这样能勉强实现图片放大和缩小功能,但图片会失真。
还有一种就是显示不同的图片,来实现放大缩小的功能。就是点击放大按钮后就换一张同样内容的大图,点击缩小按钮换上一张同样内容的小图。这样实现不好的地方在于只有两个大小。
2、将图片存进数据库后,再取出来显示到jsp页面中
  byte[] imageBytes =   ............//从数据库里取出图片
  OutputStream out = response.getOutputStream();
  out.write(imageBytes);
  out.flush();
  out.close();
这段代码就可以将图片输出到jsp页面上。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表