resizing animated GIF while keeping it's animation using java

后端 未结 3 1442
暗喜
暗喜 2020-12-30 14:00

i am using Graphics2D in java to resize images, it works perfect with jpg,png and other formats. my problem is the animated GIF images, after re-sizing the animation is gone

3条回答
  •  温柔的废话
    2020-12-30 15:07

    So I know this is old but I found a solution, I am using Java 8 not sure if it will work with other versions.

        ImageIcon image = ? (whatever/wherever your gif is)
        int width = 100;
        int height = 100;
        image.setImage(image.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT));
    

    you can change SCALE_DEFAULT to the ones listed here except for SCALE_SMOOTH and SCALE_AREA_AVREAGING didn't work for me, it was blank https://docs.oracle.com/javase/7/docs/api/java/awt/Image.html

提交回复
热议问题