-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextOnGifTest.java
53 lines (43 loc) · 1.53 KB
/
TextOnGifTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package experimentation;
import org.junit.jupiter.api.Test;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class TextOnGifTest {
private static final String defenestrateGif = "JaredVM_data/Experimentation/Images/defenestrate-window.gif";
private static final String defenestrateFrames = "JaredVM_data/Experimentation/Images/Defenestrate Frames/";
@Test
public void outputAllFrames() {
ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
ImageInputStream gifStream;
try {
gifStream = ImageIO.createImageInputStream(new File(defenestrateGif));
} catch (IOException e) {
e.printStackTrace();
return;
}
reader.setInput(gifStream, false);
ArrayList<BufferedImage> images = new ArrayList<>();
for (int i = 0; true; i++) {
try {
images.add(reader.read(i));
}
catch (IndexOutOfBoundsException | IOException e) {
break;
}
}
for (int i = 0; i < images.size(); i++) {
// Output Image
try {
ImageIO.write(images.get(i), "PNG", new File(defenestrateFrames + String.format("%02d", i) + ".png"));
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}