Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the gif picture size in android

Now I know how to draw a GIF picture in android, here is the code:

public class GIFView extends View{        
private Movie movie;  
private InputStream is;  
private long moviestart;  
public GIFView(Context context) {  
    super(context);
    is=getResources().openRawResource(R.drawable.anim_cerca);  
    movie=Movie.decodeStream(is);
}  

@Override  
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    long now=android.os.SystemClock.uptimeMillis();  

    if (moviestart == 0) 
        moviestart = now;  

    int relTime = (int)((now - moviestart) % movie.duration());
    movie.setTime(relTime);
    movie.draw(canvas,10,10);
    this.invalidate();
}  

}

At the end, there is the movie.draw(canvas,x,y) code, where the x and y is the coordinate for the gif picture (x=left, y=top). But how could I change the width and the height of the movie? Maybe give the right and bottom coordinates, but how, where? Thank you!

like image 523
victorio Avatar asked Dec 17 '12 23:12

victorio


1 Answers

i had the same problem here is my solution, add this code in ondraw method before movie.draw

 canvas.scale((float)this.getWidth() / (float)movie.width(),(float)this.getHeight() /      (float)movie.height());

or

canvas.scale(1.9f, 1.21f);//this changes according to screen size 
like image 148
Alp Avatar answered Sep 23 '22 17:09

Alp