When trying to rotate an image: Cannot resolve method mtx.postRotate(int)

Viewed 1147

I am taking an image from my camera intent but the problem is, it is coming in Landscape mode even when I take the image in portrait mode.

To solve this, I tried to rotate the image but I am getting this error (Mentioned below).

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        int screenWidth = getResources().getDisplayMetrics().widthPixels;
        int screenHeight = getResources().getDisplayMetrics().heightPixels;
        File imgFile = new  File(pictureImagePath);
        if(imgFile.exists()){
            Bitmap bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

            //Rotate image
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                // Notice that width and height are reversed
                Bitmap scaled = ScalingUtilities.createScaledBitmap(bm, screenHeight, screenWidth, ScalingUtilities.ScalingLogic.FIT);
                int w = scaled.getWidth();
                int h = scaled.getHeight();
                // Setting post rotate to 90
                Matrix mtx = new Matrix(); 
                mtx.postRotate(90); //Cannot resolve method 'postRotate(int)'
                // Rotating Bitmap
                bm = Bitmap.createBitmap(scaled, 0, 0, w, h, mtx, true);
            }else{// LANDSCAPE MODE
                //No need to reverse width and height
                Bitmap scaled = ScalingUtilities.createScaledBitmap(bm, screenHeight, screenWidth, ScalingUtilities.ScalingLogic.FIT);
                bm=scaled;
            }

            ImageView myImage = (ImageView) findViewById(R.id.imageView);
            myImage.setImageBitmap(bm);

        }
    }

Problem: mtx.postRotate(90); is showing: Cannot resolve method 'postRotate(int)'

Any help?

Feel free to suggest edits. Any help is appreciated.

1 Answers
Related