Created
March 19, 2016 06:39
-
-
Save bearprada/0bfc303803460f5c0130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Giffle.GiffleBuilder builder = new Giffle.GiffleBuilder() | |
.size(320, 480) // otuput image size 320x480 | |
.delay(100) // 100 ms | |
.file(File.createTempFile("PicCollage", "gif")); | |
final Giffle encoder = builder.build(); | |
List<Bitmap> bitmaps = getOutputBitmaps(); // please impelemnt this block by youself | |
int[] colors = getTrainingPixels(bitmaps, pw, ph, totalFrame, frameMs); // this part is tricky | |
encoder.GenPalette(colors.length, colors); | |
for (Bitmap bm : bitmaps) { | |
encoder.AddFrame(bm); | |
} | |
encoder.Close(); | |
// END | |
private int[] getTrainingPixels(final List<Bitmap> bitmaps, int width, int height) { | |
int trainingWidth = width / 2; | |
int trainingHeight = height / 2; | |
int frameLen = trainingWidth * trainingHeight; | |
int[] tmp = new int[frameLen]; | |
int[] multiImagePixels = new int[frameLen * frameNum]; | |
for (Bitmap bm : bitmaps) { | |
bm.getPixels(tmp, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight()); | |
System.arraycopy(tmp, 0, multiImagePixels, frameLen * i, pp.length); | |
} | |
return multiImagePixels; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment