jsp处理图片

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 οnclick="enlarge('image');return true;">放大</button><button οnclick="shrink('image');return true;">缩小</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页面上。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值