2013-05-27 8 views
1

이미지를 어느 정도 회전시키고 배경을 붉은 색으로 채우려고합니다. 예를 들어 나는 이미지를 가지고 있으며 15 분 (45도)까지 작은 이미지를 회전시키고 그 반원을 붉은 색으로 표시하려고합니다.배경색으로 이미지를 회전하는 방법은 무엇입니까?

다음 코드를 사용하여 일부 회전 각도를 회전 시켰지만 배경색을 채울 수 없습니다. 도와주세요.

RotateAnimation rotateAnimation = new RotateAnimation(
       (1 - 1) * 6, 10 * 6, 
       Animation.RELATIVE_TO_SELF, 0.5f, 
       Animation.RELATIVE_TO_SELF, 0.5f); 

     rotateAnimation.setInterpolator(new LinearInterpolator()); 
     rotateAnimation.setDuration(5000); 
     rotateAnimation.setFillEnabled(true); 
     rotateAnimation.setFillBefore(true); 
     rotateAnimation.setBackgroundColor(Color.RED); 
     orgClockImage.startAnimation(rotateAnimation); 

감사

+0

listview를 사용하고 있습니까? 그렇다면이 링크가 도움이 될 수 있습니다. http://stackoverflow.com/questions/15593152/rotating-images-in-listview –

+0

아니요 listview를 사용하고 있지 않습니다. 나는 시계와 같은 이미지 뷰를 가지고 있으며, 분노 한 Niddler를 회전시키고 싶다. – Monali

답변

0

당신은 또한 매트릭스와 비트 맵을 회전 할 수 있습니다.

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; 
    } 
} 
} 
+0

나를 위해 일하지 않았다. – Monali

관련 문제