2013-02-26 6 views
2

커스텀 ImageView가 있습니다. 이미지 뷰를 약간 각도로 회전하고 싶습니다. 다음은 onDraw() 메서드입니다.이미지 뷰 회전 후 양쪽에서 자르기

canvas.save(); 
canvas.rotate(currentAngle,getWidth()/2,getHeight()/2); 
super.onDraw(canvas); 

이미지가 회전 중이지만 회전 후 이미지가 측면에서 자릅니다. 절단하는 것을 피하는 법?

샘플 스크린 샷 : 다음 코드 enter image description here

+0

애니메이션이나 매트릭스를 통해이를 수행 할 수 있습니다. 이 링크 확인 http://stackoverflow.com/questions/8981845/androidrotate-image-in-imageview-by-an-angle – Gyonder

답변

0

시도 :

public class bitmaptest extends Activity { 
    @Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     LinearLayout linLayout = new LinearLayout(this); 

     // load the origial BitMap (500 x 500 px) 
     Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
       R.drawable.android); 

     int width = bitmapOrg.width(); 
     int height = bitmapOrg.height(); 
     int newWidth = 200; 
     int newHeight = 200; 

     // calculate the scale - in this case = 0.4f 
     float scaleWidth = ((float) newWidth)/width; 
     float scaleHeight = ((float) newHeight)/height; 

     // createa matrix for the manipulation 
     Matrix matrix = new Matrix(); 
     // resize the bit map 
     matrix.postScale(scaleWidth, scaleHeight); 
     // rotate the Bitmap 
     matrix.postRotate(45); 

     // recreate the new Bitmap 
     Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
          width, height, matrix, true); 

     // make a Drawable from Bitmap to allow to set the BitMap 
     // to the ImageView, ImageButton or what ever 
     BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); 

     ImageView imageView = new ImageView(this); 

     // set the Drawable on the ImageView 
     imageView.setImageDrawable(bmd); 

     // center the Image 
     imageView.setScaleType(ScaleType.CENTER); 

     // add ImageView to the Layout 
     linLayout.addView(imageView, 
       new LinearLayout.LayoutParams(
         LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT 
       ) 
     ); 

     // set LinearLayout as ContentView 
     setContentView(linLayout); 
    } 
    } 
0

내가 비슷한 문제가 한 번이었다. 나는이 문제가 방법이라고 결정되었다. 나는 그것이


처럼 보였다 너무에서 이미지를 확대 | _ __ | | | | | | | _ | | | _ __ _ |

왼쪽과 오른쪽에 절반 너비 이미지가 추가되었습니다. 그리고 절반 높이가 위아래를 더했습니다. 새로운 공간이 약간의 색을 채우거나 alapha canal이 + 0이됩니다. 이미지를 회전 할 때 초과를 잘라야합니다. 나는 안드로이드가 아니라 그것을했지만, 이것이 당신을 도울 수 있기를 바랍니다.

관련 문제