1

Why when I load an image from the gallery with the intent, this is not rotated. As if viewed through the Android Gallery that is rotated?

===========================================

I solved this way:

int orientation=getOrientationImageFile();

    Canvas c=new Canvas(bmO);

    if(orientation!=0){
        Matrix matrix=new Matrix();
        matrix.setRotate(orientation);
        c.drawBitmap(bm, matrix, new Paint());

        bm=Bitmap.createBitmap(bmO, 0, 0, bmO.getWidth(), bmO.getHeight(), matrix, true);
    }

private int getOrientationImageFile() {
        String[] proj = { MediaStore.Images.Media.ORIENTATION };
        Cursor cursor = managedQuery(selectedImageUri, proj, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.ORIENTATION);
        cursor.moveToFirst();
        return cursor.getInt(column_index);
}

selectedImageUri-it's the DATA returned from intent Gallery

bmO-bitmap created by selectedImageUri

I tried and tried and it works, but is the solution, or is it a solution that can go? There are other better solutions?

  • Please elaborate more on your issue. – coder_For_Life22 Jan 01 '12 at 21:32
  • @ coder_For_Life22 For example, if I take a picture with the phone in landscape pictures in the Gallery Android is displayed good, but if I load the intent Gallery, this is not rotated and there is quite a bit of black border above and below the image. It happens regardless of whether the automatic screen rotation is set or not. – Gioacchino Del Prete Jan 01 '12 at 21:42

1 Answers1

1

Because Android gallery app do it for you. So, you need to implement such thing by yourself

Don't worry - it's easy: How to crop and rotate image programmatically in android?

Community
  • 1
  • 1
Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146