Monday, February 15, 2016

Android Image Rotation

Note: Don't forget to create ImageView in your layout xml file with android:id="@+id/imageView1
/*** Rotate image to 45 degrees.*/    public void RotateImage(){
    ImageView image;    Bitmap bMap;    Matrix matrix;
    //Get ImageView from layout xml file    image = (ImageView) findViewById(R.id.imageView1);
    //Decode Image using Bitmap factory.    bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    //Create object of new Matrix.    matrix = new Matrix();
    //set image rotation value to 45 degrees in matrix.    matrix.postRotate(45);
    //Create bitmap with new values.    Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,    bMap.getWidth(), bMap.getHeight(), matrix, true);
    //put rotated image in ImageView.    image.setImageBitmap(bMapRotate);    }
source:http://droid-examplecode.blogspot.pt/2012/01/android-image-rotation_01.html

No comments:

Post a Comment