⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagetourexample.java

📁 java对GIF的编解码工具,有完整的说明和例子
💻 JAVA
字号:

import com.gif4j.light.GifEncoder;
import com.gif4j.light.GifFrame;
import com.gif4j.light.GifImage;

import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * This example demostrates how to create a simple image tour.
 */

public class ImageTourExample {

    public static void main(String[] args) {

        // change out directory if it is necessary
        File outputDir = new File("." + File.separator + "result");
        if (!outputDir.exists())
            outputDir.mkdirs();
        try {
            // read images. Here we read from files but it can be any source (internet, database etc.)
            Image[] images = new Image[4];
            for (int i = 1; i <= 4; i++)
                images[i - 1] = Toolkit.getDefaultToolkit().createImage("house_"+i+".jpg");
            // create gif image
            GifImage gifImage = new GifImage(160, 120, GifImage.RESIZE_STRATEGY_SCALE_TO_FIT_IMAGE_SIZE);
            // set indefinite looping
            gifImage.setLoopNumber(0);
            // create and add GifFrames in loop
            for (int i = 0; i < images.length; i++) {
                GifFrame nextFrame = new GifFrame(images[i]);
                gifImage.addGifFrame(nextFrame);
            }
            // set longer delay (5 seconds) for the last frame
            gifImage.getLastFrame().setDelay(500);
            // encode gif image
            GifEncoder.encode(gifImage, new File(outputDir, "ImageTourExample.gif"), true);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -