Skip to content

Instantly share code, notes, and snippets.

@dezmaeth
Created October 30, 2014 04:53
Show Gist options
  • Save dezmaeth/b024658b880e688b47d6 to your computer and use it in GitHub Desktop.
Save dezmaeth/b024658b880e688b47d6 to your computer and use it in GitHub Desktop.
GifRun class fixed for transparency
// Created by JeffMeJones@gmail.com
package gif.decoder;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
public class GifRun implements Runnable, Callback {
public Bitmap bmb;
public GIFDecode decode;
public int ind;
public int gifCount;
public SurfaceHolder mSurfaceHolder ;
boolean surfaceExists;
public void LoadGiff(SurfaceView v, android.content.Context theTHIS, int R_drawable)
{
//InputStream Raw= context.getResources().openRawResource(R.drawable.image001);
mSurfaceHolder = v.getHolder();
mSurfaceHolder.addCallback(this);
decode = new GIFDecode();
decode.read(theTHIS.getResources().openRawResource(R_drawable));
ind = 0;
// decode.
gifCount = decode.getFrameCount();
bmb = decode.getFrame(0);
surfaceExists=true;
Thread t = new Thread(this);
t.start();
}
public void run()
{
while (surfaceExists) {
try {
Canvas rCanvas = mSurfaceHolder.lockCanvas();
Paint clearPaint = new Paint ();
rCanvas.drawRect (0, 0, 800, 480, clearPaint);
clearPaint.setXfermode (new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
rCanvas.drawColor (Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
rCanvas.drawBitmap(bmb, 0, 0, new Paint());
mSurfaceHolder.unlockCanvasAndPost(rCanvas);
bmb = decode.next();
Thread.sleep(50);
} catch (Exception ex) {
}
}
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height)
{
}
public void surfaceCreated(SurfaceHolder holder)
{
}
public void surfaceDestroyed(SurfaceHolder holder) {
surfaceExists=false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment