[英]How to change the size of image with given new height and width using java?
这是我的demo.jsp页面,其中我有两个字段可以提供新的高度和宽度以更改新的高度和宽度。有人可以告诉我该怎么做吗?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ImageSizeModification</title>
<script>
function ImageResizer() {
console.log('called');
var srcImg = document.getElementById("imgID").value;
var newImg = new Image();
newImg.src = srcImg;
var height = newImg.height;
var width = newImg.width;
var newWidth = document.getElementById("widthID").value;
var newHeight = document.getElementById("HeightID").value;
console.log(newImg, srcImg, newWidth, newHeight, height, width);
}
</script>
</head>
<body>
<%
out.println("<table>");
out.println("<tr><td><input type='file' id='imgID'></td></tr>");
out.println("<tr><td>Enter new Width:</td><td><input type='text' id='widthID'></td></tr>");
out.println("<tr><td>Enter new Height:</td><td><input type='text' id='HeightID'></td></tr>");
out.println("<tr><td><input type='button' value='Submit' onclick='ImageResizer()'></td></tr>");
out.println("</table>");
%>
</body>
如果我理解正确,您要做的是在浏览器中调整图像的大小,以便将较小的文件上传到服务器。 如果是这样,那么这不是Java / JSP问题,而是Javascript问题。
这篇文章讨论了如何使用javascript库做到这一点,我认为这可能会解决您的问题。
document.getElementById("imgID").style.height = parseInt(newWidth) ;
document.getElementById("imgID").style.width = parseInt(newHeight) ;
在控制台日志之前添加以上两行。
或使用Jquery
$('#imgID').width(700);
$('#imgID').height(700);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.