我有一个gif,由Movie Class在画布上运行。如何根据屏幕尺寸改变电影的大小?我尝试用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);
}
}
}
感谢您的任何建议。
答案 0 :(得分:0)
我使用canvas.scale()并且它可以工作。
答案 1 :(得分:0)
您可以使用:
canvas.scale(
(float)getMesuredWidth()/movie.width(),
(float)getMesuredHeight()/movie.height()
);
对我有用