Question

When i am downloading image from server using respective url, image gets download perfectly, but issue is that downloaded image has orientation changed, how to handle this thing, how do i change orientation of image? Thanks in advance.

Was it helpful?

Solution 2

Just rotate the Image in opposite direction by using

Matrix matrix=new Matrix();
imageView.setScaleType(ScaleType.MATRIX);   //required
float angle = 180f;//Use your value
matrix.postRotate( angle, imageView.getDrawable().getBounds().width()/2, imageView.getDrawable().getBounds().height()/2);
imageView.setImageMatrix(matrix);

OTHER TIPS

First of all save that image to your sdcard and then try below code, and see if its working or not. For me its working perfectly.

File f = new File(filePath);
ExifInterface exif = new ExifInterface(f.getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

int angle = 0;

if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
angle = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
angle = 180;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
angle = 270;
}

Matrix mat = new Matrix();
mat.postRotate(angle);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;

ExifInterface is used to rotate the image in android

ExifInterface exif;
    try {
        exif = new ExifInterface(filePath);

        int orientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION, 0);
        Log.d("EXIF", "Exif: " + orientation);
        Matrix matrix = new Matrix();
        if (orientation == 6) {
            matrix.postRotate(90);
            Log.d("EXIF", "Exif: " + orientation);
        } else if (orientation == 3) {
            matrix.postRotate(180);
            Log.d("EXIF", "Exif: " + orientation);
        } else if (orientation == 8) {
            matrix.postRotate(270);
            Log.d("EXIF", "Exif: " + orientation);
        }
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                bmp.getHeight(), matrix, true);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top