1
我有一個gif,由電影類運行在畫布上。我如何根據屏幕尺寸改變電影尺寸?我試着用canvas.scale()
但GIF disappeard來改變它,如果我改變了高度比1.1大的值..Android如何改變電影尺寸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);
}
}
}
感謝您的任何建議。
您好,歡迎來到Stack Overflow,感謝您分享您的解決方案。如果你在答案中提供了一些示例代碼,它可能會對用戶有所幫助,因爲相同的功能似乎不適合他。 – tfv
它不起作用,我在問題中提到它。 –