Skip to content Skip to sidebar Skip to footer

Image Orientation Changes While Uploading Image To Server

I am using following code to upload image to server,it is successfully uploaded but image orientation changing with -90. I didnt understand how to solve this issue. My image in Sd

Solution 1:

There is unfortunately no way of modifying the orientation of the photo file other other than to load the image, rotate it manually and re-save it in it's correct orientation.

You can refer this code for image rotation samples:

introtate=0;
try {
    getContentResolver().notifyChange(imageUri, null);
    FileimageFile=newFile(al_image_paths.get(i)); 
    ExifInterfaceexif=newExifInterface(imageFile.getAbsolutePath());
    intorientation= exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

    switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_270:
            rotate = 270;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            rotate = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            rotate = 90;
            break;
    }
    Log.v(Common.TAG, "Exif orientation: " + orientation);

    Bitmap rotattedBitmap= BitmapFactory.decodeFile(al_image_paths.get(i));           
    Matrixmatrix=newMatrix();
    matrix.postRotate(rotate);
    return Bitmap.createBitmap(rotattedBitmap, 0, 0, rotattedBitmap.getWidth(), rotattedBitmap.getHeight(), matrix, true);
} catch (Exception e) {
    e.printStackTrace();
}

EDIT: In your case, you have to do following:

  1. Identify image EXIF orientation
  2. Create the bitmap
  3. Rotate the bitmap
  4. Save the bitmap as image
  5. Upload image to server

Solution 2:

use that code

ExifInterface exif;
intangle=0;
try {
    exif = newExifInterface(myUri.getPath());
    intorientation= exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
        angle = 90;
    } elseif (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
        angle = 180;
    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Matrixmatrix1=newMatrix();

//set image rotation value to 45 degrees in matrix.
matrix1.postRotate(angle);

//Create bitmap with new values.Bitmapphoto= Bitmap.createBitmap( bitmap, 0, 0, bitmap.getWidth(),  bitmap.getHeight(), matrix1, true);

Post a Comment for "Image Orientation Changes While Uploading Image To Server"