2014-04-29 2 views
0

비트 맵을 회전하면 회전하지만 화면 전체를 계속 움직이고 동시에 회전합니다. 나는 중심에서 회전시키고 싶습니까? 내 코드는 아래와 같습니다.비트 맵의 ​​위치 지정

try { 
    c = holder.lockCanvas(); 
    // clear the canvas 
    c.drawColor(Color.BLACK); 
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); 
    if (c != null) { 

     int width=c.getWidth(); 
     int height=c.getHeight(); 

     c.drawBitmap(backgroundImage, 0, 0, null); 
     Matrix transform = new Matrix(); 
     Matrix transform1=new Matrix(); 

     transform.setRotate(degree, width/2,height/2); 
     c.drawBitmap(image1, transform, null); 
     //canvas.rotate(-90); 

     degree+=5; 
     c.restore(); 
    } 
} 

답변

1

이 코드를보십시오 ..

  c = holder.lockCanvas(); 
      c.drawColor(Color.BLACK); 
      Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG); 
       if (c != null) 
        { 
        int width=c.getWidth(); 
        int height=c.getHeight(); 
        c.drawBitmap(backgroundImage, 0, 0, null); 

        Matrix matrix = new Matrix(); 

        float px = width/2; 

        float py = height/2; 

        matrix.postTranslate(-image1.getWidth()/2, -image1.getHeight()/2); 

        matrix.postRotate(degree); 

        matrix.postTranslate(px, py); 

        c.drawBitmap(image1, matrix, paint); 

         degree+=5; 

         c.restore(); 
      } 
관련 문제