I am trying to use this Android Gif Encoder https://github.com/nbadal/android-gif-encoder/blob/master/GifEncoder.java
I'm having errors trying to implement this in my android app.
the following errors are:
outStream.write(generateGIF()); Description Resource Path Location Type The method generateGIF() is undefined for the type new View.OnClickListener(){} Main.java /f/src/net/s/f line 197 Java Problem
public boolean finish() { Description Resource Path Location Type The return type is incompatible with Activity.finish() AnimatedGifEncoder.java /f/src/net/s/f line 164 Java Problem
public byte[] onClick(View v) { Description Resource Path Location Type The return type is incompatible with View.OnClickListener.onClick(View) Main.java /f/src/net/s/f line 180 Java Problem
my code is below:
save.setOnClickListener(new OnClickListener() {
@Override
public byte[] onClick(View v) {
// TODO Auto-generated method stub
ArrayList<Bitmap> bitmaps = adapter.getBitmapArray();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(bos);
for (Bitmap bitmap : bitmaps) {
encoder.addFrame(bitmap);
}
encoder.finish();
return bos.toByteArray();
FileOutputStream outStream = null;
try{
outStream = new FileOutputStream("/sdcard/generate_gif/test.gif");
outStream.write(generateGIF());
outStream.close();
}catch(Exception e){
e.printStackTrace();
}
Toast.makeText(Main.this, "Saved.", Toast.LENGTH_SHORT).show();
}
});
///////////////////////////////////////////////////////////////
To use this class, here is an example helper method to generate GIF byte array. Note here the getBitmapArray() function is a method to return all the Bitmap files in an image adapter at once. So the input is all the Bitmap files in one adapter, the output is a byte array which you can write to the file.
public byte[] generateGIF() {
ArrayList<Bitmap> bitmaps = adapter.getBitmapArray();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(bos);
for (Bitmap bitmap : bitmaps) {
encoder.addFrame(bitmap);
}
encoder.finish();
return bos.toByteArray();
}
To use this function, do the following then you can save the file into SDcard.
FileOutputStream outStream = null;
try{
outStream = new FileOutputStream("/sdcard/generate_gif/test.gif");
outStream.write(generateGIF());
outStream.close();
}catch(Exception e){
e.printStackTrace();
}
On click() return type must be void.