Skip to content

Instantly share code, notes, and snippets.

@bearprada
Created March 19, 2016 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearprada/0bfc303803460f5c0130 to your computer and use it in GitHub Desktop.
Save bearprada/0bfc303803460f5c0130 to your computer and use it in GitHub Desktop.
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