如何在安卓上改变电影大小GIF

3

我有一个gif,通过Movie类在画布上运行。如何根据屏幕的大小按比例更改电影的大小?我尝试使用canvas.scale()进行更改,但如果将高度更改为大于1.1的值,则该gif会消失。

下面是代码:

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);
            }
        }
}

感谢您提供的任何建议。
2个回答

1
您可以使用:

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

它对我起作用了


0

我使用canvas.scale(),它可以正常工作。


你好,欢迎来到 Stack Overflow,并感谢您分享您的解决方案。如果您在答案中提供一些示例代码,可能会对该用户有所帮助,因为相同的函数似乎对他不起作用。 - tfv

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接