?? resizestrategiesexample.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 {@link com.gif4j.light.GifImage} resize strategies usage and differences.
*/
public class ResizeStrategiesExample {
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 {
GifImage imageWithExtendToCurrentResizeStrategy = new GifImage(GifImage.RESIZE_STRATEGY_EXTEND_TO_CURRENT);
// set indefinite looping
imageWithExtendToCurrentResizeStrategy.setLoopNumber(0);
// 100x100 frame 1 at position (0,0)
imageWithExtendToCurrentResizeStrategy.addGifFrame(
new GifFrame(TestUtils.genTestImage(100, 100)));
// 50x50 frame 2 at position (150,150)
imageWithExtendToCurrentResizeStrategy.addGifFrame(
new GifFrame(TestUtils.genTestImage(150, 150), new Point(50, 50)));
// 100x100 frame 3 at position (100,100)
imageWithExtendToCurrentResizeStrategy.addGifFrame(
new GifFrame(TestUtils.genTestImage(100, 100), new Point(100, 100)));
GifEncoder.encode(imageWithExtendToCurrentResizeStrategy, new File(outputDir, "ResizeStrategiesExample_extend_to_current.gif"), true);
GifImage imageWithCropToFitImageSize = new GifImage(150, 150, GifImage.RESIZE_STRATEGY_CROP_TO_FIT_IMAGE_SIZE);
// set indefinite looping
imageWithCropToFitImageSize.setLoopNumber(0);
// 100x100 frame 1 at position (0,0)
imageWithCropToFitImageSize.addGifFrame(
new GifFrame(TestUtils.genTestImage(100, 100)));
// 50x50 frame 2 at position (150,150)
imageWithCropToFitImageSize.addGifFrame(
new GifFrame(TestUtils.genTestImage(150, 150), new Point(50, 50)));
// 100x100 frame 3 at position (100,100)
imageWithCropToFitImageSize.addGifFrame(
new GifFrame(TestUtils.genTestImage(100, 100), new Point(100, 100)));
GifEncoder.encode(imageWithCropToFitImageSize, new File(outputDir, "ResizeStrategiesExample_crop_to_fit.gif"), true);
GifImage imageWithScaleToFitImageSize = new GifImage(150, 150, GifImage.RESIZE_STRATEGY_SCALE_TO_FIT_IMAGE_SIZE);
// set indefinite looping
imageWithScaleToFitImageSize.setLoopNumber(0);
// 100x100 frame 1 at position (0,0)
imageWithScaleToFitImageSize.addGifFrame(
new GifFrame(TestUtils.genTestImage(100, 100)));
// 50x50 frame 2 at position (150,150)
imageWithScaleToFitImageSize.addGifFrame(
new GifFrame(TestUtils.genTestImage(150, 150), new Point(50, 50)));
// 100x100 frame 3 at position (100,100)
imageWithScaleToFitImageSize.addGifFrame(
new GifFrame(TestUtils.genTestImage(100, 100), new Point(100, 100)));
GifEncoder.encode(imageWithScaleToFitImageSize, new File(outputDir, "ResizeStrategiesExample_scale_to_fit.gif"), true);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -