大佬教程收集整理的这篇文章主要介绍了在Grails中调整图像大小,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import java.awt.Image as AWtimage
import java.awt.image.bufferedImage
import javax.swing.ImageIcon
import javax.imageio.ImageIO as IIO
import java.awt.Graphics2D
static resize = { bytes, out, maxW, maxH ->
AWtimage ai = new ImageIcon(bytes).image
int wIDth = ai.getWIDth( null )
int height = ai.getHeight( null )
def limits = 300..2000
assert limits.contains( wIDth ) && limits.contains( height ) : 'Picture is either too small or too big!'
float aspectRatio = wIDth / Height Float requiredAspectRatio = maxW / maxH
int dstW = 0
int dstH = 0
if (requiredAspectRatio < aspectRatio) {
dstW = maxW dstH = Math.round( maxW / aspectRatio)
} else {
dstH = maxH dstW = Math.round(R_521_11845@axH * aspectRatio)
}
BufferedImage bi = new BufferedImage(dstW, dstH, BufferedImage.TYPE_INT_RGB)
Graphics2D g2d = bi.createGraphics() g2d.drawImage(ai, 0, 0, dstW, dstH, null, null)
IIO.write( bi, 'JPEG', out )
}
我正在使用Grails开发网络相册,并且用于图像处理,正在使用grails-image-tools插件。如果上传的图像太大(例如:大于600 * 840),我需要一种功能来调整图像的大小。在这种情况下,我需要将此图像调整为600 * 840)。最有效的方法是什么?非常感谢。
以上是大佬教程为你收集整理的在Grails中调整图像大小全部内容,希望文章能够帮你解决在Grails中调整图像大小所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。