gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:24:14 24 4
gpt4 key购买 nike

您如何在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, 0, 0, newWidth, newHeight, null )
dispose()
}
ImageIO.write( i, 'png', new File( '/tmp/scaled.png' ) )
}

关于image - 如何在Groovy中调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10350984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com