你如何在Groovy中调整图像大小?

你如何在Groovy中调整/缩小JPG图像的大小?

解决方法

或者,如果您不想加载外部依赖项,只需正常执行:

import static java.awt.RenderingHints.*
import java.awt.image.BufferedImage
import javax.imageio.ImageIO

def img = ImageIO.read( new File( '/tmp/image.png' ) )

def scale = 0.5

int newWidth = img.width * scale
int newHeight = img.height * scale

new BufferedImage( newWidth,newHeight,img.type ).with { i ->
  createGraphics().with {
    setRenderingHint( KEY_INTERPOLATION,VALUE_INTERPOLATION_BICUBIC )
    drawImage( img,newWidth,null )
    dispose()
  }
  ImageIO.write( i,'png',new File( '/tmp/scaled.png' ) )
}

相关文章

背景:    8月29日,凌晨4点左右,某服务告警,其中一个...
https://support.smartbear.comeadyapi/docs/soapui/steps/g...
有几个选项可用于执行自定义JMeter脚本并扩展基线JMeter功能...
Scala和Java为静态语言,Groovy为动态语言Scala:函数式编程,...
出处:https://www.jianshu.com/p/ce6f8a1f66f4一、一些内部...
在运行groovy的junit方法时,报了这个错误:java.lang.Excep...