Showing posts with label Image. Show all posts
Showing posts with label Image. Show all posts

Sunday, 1 January 2012

Android Image Rotation

Description:


Below method will rotate image to 45 degrees.

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, 00,
                bMap.getWidth(), bMap.getHeight(), matrix, true);
        
        //put rotated image in ImageView.
        image.setImageBitmap(bMapRotate);
    }