简体   繁体   English

如何在使用tapestry5存储之前调整图像大小

[英]How to resize an image before storing using tapestry5

I am using tapestry5 framework, in which I am using uploadedFile component which is returning me a file which is type of an image.我正在使用tapestry5 框架,其中我使用了uploadedFile 组件,该组件返回一个图像类型的文件。

Now I want to resize that image to 20 x 20, irrespective of the type of the image.现在我想将该图像的大小调整为 20 x 20,而不考虑图像的类型。

Is there any way with Java API or with Tapestry5 framework to achieve this?有没有办法用 Java API 或 Tapestry5 框架来实现这一点?

This is not functionality that is part of Tapestry, or every likely to be.这不是 Tapestry 的一部分,也不是所有可能的功能。 The Java2D API has more than sufficient support for converting byte streams into images, rescaling them, and storing them back out. Java2D API 对将字节流转换为图像、重新缩放和存储它们提供了足够的支持。

Try this:试试这个:

BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM