2010-06-03 4 views
0

길이가 30 x 60 픽셀 인 이미지가 있습니다. 위 이미지를 이미지의 아래쪽 중심 주위로 회전하고 싶습니다. 예 : 위의 피벗을 설정하고 싶습니다. 예 : (15, 60) 픽셀.이미지 회전 지점

나는 이것을하기 위해 drawble과 matrix를 사용하고 있는데, 무엇이든 나는 항상 이미지 중심을 중심으로 회전한다.

코드 :

Bitmap bitmapOrg = BitmapFactory.decodeFile("/sdcard/DCIM/2010-06-01_15-32-42_821.jpg"); 

// 플로트 각도 = (각도 + 10.0f) 360.0f %; (! = null의 bitmapOrg 있으면) {

   int width = bitmapOrg.getWidth(); 
      int height = bitmapOrg.getHeight(); 
      int newWidth = 15; 
      int newHeight = 15; 

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

/* 캔버스 C = 새로운 캔버스 (bitmapOrg); float px =; float py; c.rotate (각도, PX, PY) */

   // 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); 

// imageView.layout (100, 300, 0, 0); // linLayout.addView (imageView);

   // add ImageView to the Layout 
      linLayout.addView(imageView, 
       new AbsoluteLayout.LayoutParams(
          LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 10, 30 
        ) 
      ); 

아무도 내가이 정류 방법을 알 수 있습니까?

답변

0

회전하기 전에 회전하려는 지점으로 이동하고 있습니까?

체크 아웃이 자원 : 당신이 영상을 회전 할 수 있습니다 매트릭스의 도움으로 http://blogs.sonyericsson.com/developerworld/2010/05/31/android-tutorial-making-your-own-3d-list-part-2/

+0

위의 URL이 누락되었습니다 ... – RRTW

+0

이것은 3 년되지 않았습니다. 나는 문자 그대로 사이트에 가서 깨진 링크에서 키워드를 검색했다 : http://developer.sonymobile.com/2010/05/31/android-tutorial-making-your-own-3d-list-part- 2 / –

0

예를. RotateBitmap()을 호출 한 후 getBitmap()을 사용하여 언제든지 비트 맵을 가져올 수 있습니다.

public class RotateBitmap { 

public static final String TAG = "RotateBitmap"; 
private Bitmap     mBitmap; 
private int      mRotation; 
private int      mWidth; 
private int      mHeight; 
private int      mBitmapWidth; 
private int      mBitmapHeight; 

public RotateBitmap(Bitmap bitmap, int rotation) 
{ 
    mRotation = rotation % 360; 
    setBitmap(bitmap); 
} 

public void setRotation(int rotation) 
{ 
    mRotation = rotation; 
    invalidate(); 
} 

public int getRotation() 
{ 
    return mRotation % 360; 
} 

public Bitmap getBitmap() 
{ 
    return mBitmap; 
} 

public void setBitmap(Bitmap bitmap) 
{ 
    mBitmap = bitmap; 

    if (mBitmap != null) { 
     mBitmapWidth = bitmap.getWidth(); 
     mBitmapHeight = bitmap.getHeight(); 
     invalidate(); 
    } 
} 

private void invalidate() 
{ 
    Matrix matrix = new Matrix(); 
    int cx = mBitmapWidth/2; 
    int cy = mBitmapHeight/2; 
    matrix.preTranslate(-cx, -cy); 
    matrix.postRotate(mRotation); 
    matrix.postTranslate(cx, cx); 

    RectF rect = new RectF(0, 0, mBitmapWidth, mBitmapHeight); 
    matrix.mapRect(rect); 
    mWidth = (int)rect.width(); 
    mHeight = (int)rect.height(); 
} 

public Matrix getRotateMatrix() 
{ 
    Matrix matrix = new Matrix(); 
    if (mRotation != 0) { 
     int cx = mBitmapWidth/2; 
     int cy = mBitmapHeight/2; 
     matrix.preTranslate(-cx, -cy); 
     matrix.postRotate(mRotation); 
     matrix.postTranslate(mWidth/2, mHeight/2); 
    } 

    return matrix; 
} 

public int getHeight() 
{ 
    return mHeight; 
} 

public int getWidth() 
{ 
    return mWidth; 
} 

public void recycle() 
{ 
    if (mBitmap != null) { 
     mBitmap.recycle(); 
     mBitmap = null; 
    } 
} 
}