2015-09-28 120 views
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); 
      } 
     } 
} 

感谢您的任何建议。

回答

0

我使用canvas.scale(),它的工作原理。

+0

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

+0

它不起作用,我在问题中提到它。 –