title: How do I implement the android gif encoder in my app?
body: <p>I am trying to use this Android Gif Encoder
  <a href="https://github.com/nbadal/android-gif-encoder/blob/master/GifEncoder.java" rel="nofollow">https://github.com/nbadal/android-gif-encoder/blob/master/GifEncoder.java</a></p>
  
  <p>I'm having errors trying to implement this in my android app.</p>
  
  <p>the following errors are:</p>
  
  <ol>
  <li><p>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</p></li>
  <li><p>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</p></li>
  <li><p>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</p></li>
  </ol>
  
  <p>my code is below:</p>
  
  <pre><code>save.setOnClickListener(new OnClickListener() {
  
  @Override
  public byte[] onClick(View v) {
      // TODO Auto-generated method stub              
  
  
      ArrayList&lt;Bitmap&gt; 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();
  
  }
  });
  </code></pre>
  
  <p>///////////////////////////////////////////////////////////////</p>
  
  <p>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. </p>
  
  <pre><code>public byte[] generateGIF() {
      ArrayList&lt;Bitmap&gt; 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();
  }
  </code></pre>
  
  <p>To use this function, do the following then you can save the file into SDcard. </p>
  
  <pre><code>FileOutputStream outStream = null;
          try{
              outStream = new FileOutputStream("/sdcard/generate_gif/test.gif");
              outStream.write(generateGIF());
              outStream.close();
          }catch(Exception e){
              e.printStackTrace();
          }
  </code></pre>