Guy Madmon
Guy Madmon

Reputation: 33

Android How to change Movie size GIF

I have a gif , running by Movie Class over a canvas. How can I change the size of the movie in proportion to the Screen's size? I tried to change it with canvas.scale() but the gif disappeard if I changed the height to a value bigger than 1.1 ..

Here is the code:

public class OurView extends SurfaceView implements Runnable {
        private Movie mMovie;
        InputStream mStream;

        public OurView(Context context, InputStream stream) {
            super(context);
            holder = getHolder();
            mStream = stream;
            mMovie = Movie.decodeStream(mStream);

        }

        private long mMoviestart = 0;
        Thread t = null;
        SurfaceHolder holder;
        boolean isItOK = false;

        public OurView(Context c) {
            super(c);
            holder = getHolder();
        }

        public void run() {
            while (isItOK) {
                if (!holder.getSurface().isValid()) {
                    continue;
                }
                Canvas c = holder.lockCanvas();
                try {
                    t.sleep(90);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                x -= 10;
                if (x + screenWidth <= 0) {
                    x = 0;
                }

                c.drawARGB(255, 150, 150, 10);
                c.drawBitmap(map, 0, 0, null);
                c.drawBitmap(grass, x, this.getHeight() - grassHeight, null);
                c.drawBitmap(grass, (x + screenWidth), this.getHeight() - grassHeight, null);
                final long now = SystemClock.uptimeMillis();
                if (mMoviestart == 0) {
                    mMoviestart = now;
                }
                final int relTime = (int) ((now - mMoviestart) % mMovie.duration());
                mMovie.setTime(relTime);
                mMovie.draw(c, screenWidth / 7, this.getHeight() - (grassHeight + 30));
                holder.unlockCanvasAndPost(c);
            }
        }
}

Thanks for any suggestions.

Upvotes: 3

Views: 749

Answers (2)

tr4n
tr4n

Reputation: 122

You can use:

canvas.scale(
     (float)getMesuredWidth()/movie.width(),
     (float)getMesuredHeight()/movie.height()
);

It worked for me

Upvotes: 1

di wu
di wu

Reputation: 1

I use canvas.scale() and it works.

Upvotes: 0

Related Questions