小编G.A*_*med的帖子

调整动画GIF的大小,同时使用java保持动画

我在java中使用Graphics2D来调整图像大小,它与jpg,png和其他格式完美配合.我的问题是动画GIF图像,重新调整动画后不见了!

这是我使用的方法:

    private BufferedImage doResize(int newWidth, int newHeight, double scaleX,
        double scaleY, BufferedImage source) {

    GraphicsConfiguration gc = getDefaultConfiguration();
    BufferedImage result = gc.createCompatibleImage(newWidth, newHeight, source.getColorModel().getTransparency());
    Graphics2D g2d = null;

    try {
        g2d = result.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.scale(scaleX, scaleY);
        g2d.drawImage(source, 0, 0, null);
    } finally {
        if (g2d != null) {
            g2d.dispose();
        }
    }

    return result;
}
Run Code Online (Sandbox Code Playgroud)

所以,任何线索如何在重新调整尺寸后如何保持动画GIF?谢谢.

java animation gif

7
推荐指数
2
解决办法
8235
查看次数

标签 统计

animation ×1

gif ×1

java ×1