0

我正在尝试在我从数据库中提取的 jsp 页面上设置图片的大小。

我可以得到图像,但它填满了整个页面。

谁知道怎么设置图片的大小

谢谢

这是我在我的jsp上的代码:

<%

Blob image = null;  
byte[] imgData = null;  
Connection con;
String url="jdbc:mysql://localhost:3306/comshopDatabase";
String uName="root";
String pwd="";
Class.forName("com.mysql.jdbc.Driver").newInstance();
    con=DriverManager.getConnection(url,uName,pwd);
    String sql="Select image from images WHERE id = '1' ";
    PreparedStatement stmt=con.prepareStatement(sql);

    ResultSet resultset=stmt.executeQuery();
while(resultset.next())
{

    Blob bl = resultset.getBlob("image");
    byte[] pict = bl.getBytes(1,(int)bl.length());
    response.setContentType("image/jpg");
    OutputStream o = response.getOutputStream();



%>
<TABLE BORDER="1">
<TR>
<TH>picture</TH>
</TR>
<TR>


<td>Image</td><td><%o.write(pict);%></td>
    <%o.flush();
    o.close();%>

<TD> <%= resultset.getString(2) %> </TD>
<TD><%= resultset.getString(3) %></TD>
</TR>
</TABLE>
<BR>
<%
o.flush();
o.close();
}
%>
4

1 回答 1

0

你可以使用图片缩放库,jar可以从这里下载。

下面是一个简单的例子:

int width =1200, height = 900;
BufferedImage image = ImageIO.read(<sourceFile>);// You can use InputStream as well here, in place of source file
BufferedImage thumbnail = Scalr.resize(image, Scalr.Method.SPEED, Scalr.Mode.FIT_TO_WIDTH,
                                       width, height , Scalr.OP_ANTIALIAS);
ImageIO.write(thumbnail, "jpg", new File(<destination file>)); // You can use OutputStream as well in place of destination file
于 2013-04-26T13:18:44.003 回答