Resize image while rotating image in android
        Posted  
        
            by 
                dhams
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by dhams
        
        
        
        Published on 2011-01-04T11:45:16Z
        Indexed on 
            2011/01/04
            14:53 UTC
        
        
        Read the original article
        Hit count: 396
        
android
Hi every one ,,m working with android project in which i want to rotate image along with touch to some fix pivot point ,,,i have completed all the things but i have facing one problem ,,,while m trying to rotate image the image bitmap is resize....i dont have any idea why it occur ....if somebody have den please give me idea to come over this problem....
my code is below .....
package com.demo.rotation;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
public class temp  extends Activity{
ImageView img1;
float startX;
float startX2 ;
Bitmap source;
Bitmap bitmap1 = null;
double r;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    img1 = (ImageView) findViewById(R.id.img1);
    img1.setOnTouchListener(img1TouchListener);
    bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.orsl_circle_transparent);
}
private OnTouchListener img1TouchListener = new OnTouchListener()
{
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_MOVE:
                Log.d("MOVE", "1");
                if(source!=null)
                 r = Math.atan2(event.getX() - source.getWidth(),
                        (source.getHeight() / 2) - event.getY());
                Log.i("startX" + event.getX(), "startY" + event.getY());
                     rotate(r,bitmap1, img1);
                     img1.setScaleType(ScaleType.CENTER);
                break;
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_UP:
                break;
            default :
                break;
        }
        return true;
    }
};
private void rotate(double r , Bitmap currentBitmap  ,ImageView imageView )
{
    int rotation = (int) Math.toDegrees(r);
    Matrix matrix = new Matrix();
    matrix.setRotate(rotation, currentBitmap.getWidth()/2, currentBitmap.getHeight()/2);
    source = Bitmap.createBitmap(currentBitmap, 0, 0, currentBitmap.getWidth(), currentBitmap.getHeight(), matrix, false);
    imageView.setImageBitmap(source);
    Log.i("HIGHT OF CURRENT BITMAP", ""+source.getHeight());
}
}
© Stack Overflow or respective owner