/
AnimatedGif.java
78 lines (61 loc) · 2.03 KB
/
AnimatedGif.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.sksamuel.scrimage.nio;
import com.sksamuel.scrimage.DisposeMethod;
import com.sksamuel.scrimage.ImmutableImage;
import com.sksamuel.scrimage.nio.internal.GifSequenceReader;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
public class AnimatedGif {
private final GifSequenceReader reader;
public AnimatedGif(GifSequenceReader reader) {
this.reader = reader;
}
public int getFrameCount() {
return reader.getFrameCount();
}
public Dimension getDimensions() {
return reader.getFrameSize();
}
public int getLoopCount() {
return reader.getLoopCount();
}
public Duration getDelay(int frame) {
return Duration.ofMillis(reader.getDelay(frame));
}
public DisposeMethod getDisposeMethod(int frame) {
return reader.getDisposeMethod(frame);
}
public ImmutableImage getFrame(int n) {
return ImmutableImage.wrapAwt(reader.getFrame(n));
}
public List<ImmutableImage> getFrames() {
List<ImmutableImage> frames = new ArrayList<>();
for (int k = 0; k < getFrameCount(); k++) {
frames.add(getFrame(k));
}
return frames;
}
public byte[] getBytes() throws IOException {
return reader.bytes();
}
public Path output(AnimatedImageWriter writer, String path) throws IOException {
return forWriter(writer).write(Paths.get(path));
}
public File output(AnimatedImageWriter writer, File file) throws IOException {
return forWriter(writer).write(file);
}
public Path output(AnimatedImageWriter writer, Path path) throws IOException {
return forWriter(writer).write(path);
}
public byte[] bytes(AnimatedImageWriter writer) throws IOException {
return forWriter(writer).bytes();
}
public AnimatedWriteContext forWriter(AnimatedImageWriter writer) throws IOException {
return new AnimatedWriteContext(writer, this);
}
}