我有一个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);
}
}
}
感谢您提供的任何建议。