3

I have to rotate an image in an overlay clock-wise and anti-clockwise as rotate my finger-tip on screen, Don't want to rotate at a specific angel. If any body have a solution then please help me.

Tapesh
  • 372
  • 1
  • 6
  • 17

3 Answers3

1

Check this Answer maybe helps you : How can i use RotateAnimation to rotate a circle?

Community
  • 1
  • 1
Guilherme Gregores
  • 1,050
  • 2
  • 10
  • 27
  • Very very thanks Dude... It is working very fine. But i need to rotate image on touch of multiple fingers(Mostly two) except of one. It is working fine with 1 finger but when i used 2 finger to use it's previous location changed with a blink. So can u please help me to find solution of this problem. Thanks in advance. – Tapesh May 07 '13 at 13:59
0

Try below link and check this link also before try:-

 public void Rotate(View v)
{

    ImageView img = (ImageView)findViewById(R.id.imageView01);
    Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.bharath);
// Getting width & height of the given image.
        int w = bmp.getWidth();
        int h = bmp.getHeight();
// Setting pre rotate to 90
        Matrix mtx = new Matrix();
        mtx.preRotate(90);
// Rotating Bitmap
        Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
        BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
        img.setImageBitmap(rotatedBMP);
    }
Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113
0

Try this

AndroidBitmap.java

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Spinner;

public class AndroidBitmap extends Activity {

    //private final String imageInSD = "/sdcard/er.PNG";

    ImageView myImageView;
    Spinner spinnerScale;
    SeekBar seekbarRotate;

    private static final String[] strScale 
        = {"0.2x", "0.5x", "1.0x", "2.0x", "5.0x"}; 
    private static final Float[] floatScale 
        = {0.2F, 0.5F, 1F, 2F, 5F};
    private final int defaultSpinnerScaleSelection = 2;

    private ArrayAdapter<String> adapterScale;

    private float curScale = 1F;
    private float curRotate = 0F;

    Bitmap bitmap;
    int bmpWidth, bmpHeight;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        myImageView = (ImageView)findViewById(R.id.imageview);

        spinnerScale = (Spinner)findViewById(R.id.scale);
        seekbarRotate = (SeekBar)findViewById(R.id.rotate);

        adapterScale = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, strScale);
        adapterScale.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerScale.setAdapter(adapterScale);
        spinnerScale.setSelection(defaultSpinnerScaleSelection);
        curScale = floatScale[defaultSpinnerScaleSelection];

        BitmapDrawable img = (BitmapDrawable) getResources()
                .getDrawable(R.drawable.ic_launcher);


        bitmap = img.getBitmap();//BitmapFactory.decodeFile(imageInSD);
        bmpWidth = bitmap.getWidth();
        bmpHeight = bitmap.getHeight();

        drawMatrix();

        spinnerScale.setOnItemSelectedListener(spinnerScaleOnItemSelectedListener);
        seekbarRotate.setOnSeekBarChangeListener(seekbarRotateSeekBarChangeListener);

    }

    private void drawMatrix(){

        Matrix matrix = new Matrix();
        matrix.postScale(curScale, curScale);
        matrix.postRotate(curRotate);

        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
        myImageView.setImageBitmap(resizedBitmap);

    }

    private SeekBar.OnSeekBarChangeListener seekbarRotateSeekBarChangeListener
        = new SeekBar.OnSeekBarChangeListener(){

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                curRotate = (float)progress;
                drawMatrix();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }};

    private Spinner.OnItemSelectedListener spinnerScaleOnItemSelectedListener
        = new Spinner.OnItemSelectedListener(){

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                curScale = floatScale[arg2];
                drawMatrix();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
                spinnerScale.setSelection(defaultSpinnerScaleSelection);
                curScale = floatScale[defaultSpinnerScaleSelection];
            }};
}

layout file

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Hello, Android image rotate"
    />
<Spinner
    android:id="@+id/scale"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    />
<SeekBar
    android:id="@+id/rotate"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_margin="5px"
    android:max="360"
    android:progress="0"
    />
<ImageView  
    android:id="@+id/imageview"
    android:layout_gravity="center"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scaleType="center"
    />
</LinearLayout>

Hope this helps

CRUSADER
  • 5,486
  • 3
  • 28
  • 64
  • On finger touch Umm! why didn't you said before. [Check out this link](http://stackoverflow.com/a/2939405/2345913). In here you get a co-ordinates of where your finger as touched, capture the movement, then use the above logic, I hope this solves the prob. – CRUSADER May 07 '13 at 12:18