Question: I want rotate image in both the ways Clockwise as well as Anti clock wise.
I had try but not rotate image both the way,
 so plz give me solution for my problem if you know..

Thanks in Advance.................///

Answer: 
Use the code below

```
public class Rotateimage extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);
          // or just load a resource from the res/drawable directory:
          Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.flo);

          // find the width and height of the screen:
          Display d = getWindowManager().getDefaultDisplay();
          int x = d.getWidth();
          int y = d.getHeight();

          // get a reference to the ImageView component that will display the image:
          ImageView img1 = (ImageView)findViewById(R.id.imageView1);

          // scale it to fit the screen, x and y swapped because my image is wider than it is tall
          Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, y, x, true);

          // create a matrix object
          Matrix matrix = new Matrix();

          matrix.postRotate(45, 90, 180);

          // create a new bitmap from the original using the matrix to transform the result
          Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);
                // display the rotated bitmap
          img1.setImageBitmap(rotatedBitmap);
}}

```
use this code hope it will be helpful...
you must have to write this method to do rotate operation

```
public void paintFromCenter(float angle, Canvas c) {
    Bitmap b = sprite;
    Bitmap h = b;
    Matrix matrix = new Matrix();
    matrix.postRotate(angle, h.getWidth() / 2, h.getHeight());
    matrix.postTranslate(getX(), getY());
    // canvas.drawBitmap(bitmap, matrix, new Paint());
    Bitmap bmp2 = Bitmap.createBitmap(h, 0, 0, frameWidth, frameHeight,
            matrix, true);
    c.drawBitmap(h, matrix, null);
}

```

in your program you have to write onTouchEvent() method

```
public boolean onTouchEvent(MotionEvent event) {
    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        edX = (int) event.getX();
        edY = (int) event.getY();
        if ((edX > objectSprite.getX()
                && edX < objectSprite.getX() + objectSprite.getWidth()
                && edY > objectSprite.getY() && edY < objectSprite.getY()
                + objectSprite.getHeight())) {
        }
    }
    if (action == MotionEvent.ACTION_MOVE) {
        emX = (int) event.getX();
        emY = (int) event.getY();
        if (edX < emX && angle <= 90) {
            update(canvas);
            CHAR = 'D';
        } else if (edX > emX && angle > 0) {
            update(canvas);
            CHAR = 'U';
        }
        if (edY < emY && angle <= 90) {
            update(canvas);
            CHAR = 'L';
        } else if (edY > emY && angle >= 0) {
            update(canvas);
            CHAR = 'R';
        }
    }
    return true;
}

```

and you have to create update() method to rotate your angle on touch event angle can be define as your choice. Initially i have declare 

```
int angle=1;
public void update(Canvas canvas) {
    switch (CHAR) {
    case 'D':
        angle += 1;
        break;
    case 'U':
        angle -= 1;

        break;
    case 'R':
        angle -= 1;
        break;
    case 'L':
        angle += 1;
        break;
    }

}

```

Now you have to draw your object in draw() method like this

```
public void draw() {
  objectSprite.paintFromCenter(angle, canvas);  
        }

```