降低Java中的图像分辨率

降低Java中的图像分辨率,第1张

降低Java中的图像分辨率

这是工作代码

public class ImageCompressor {    public void compress() throws IOException {        File infile = new File("Y:\img\star.jpg");        File outfile = new File("Y:\img\star_compressed.jpg");        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(     infile));        BufferedOutputStream bos = new BufferedOutputStream(     new FileOutputStream(outfile));        SeekableStream s = SeekableStream.wrapInputStream(bis, true);        RenderedOp image = JAI.create("stream", s);        ((OpImage) image.getRendering()).setTileCache(null);        RenderingHints qualityHints = new RenderingHints(     RenderingHints.KEY_RENDERING,     RenderingHints.VALUE_RENDER_QUALITY);        RenderedOp resizedImage = JAI.create("SubsampleAverage", image, 0.9,     0.9, qualityHints);        JAI.create("enpre", resizedImage, bos, "JPEG", null);    }    public static void main(String[] args) throws IOException {        new ImageCompressor().compress();    }}

这段代码对我来说很棒。如果需要调整图像大小,则可以在此处更改x和y比例J

AI.create("SubsampleAverage", image, xscale,yscale, qualityHints)
;



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5600825.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存