Gioacchino Del Prete
Gioacchino Del Prete

Reputation: 137

Android image from gallery intent

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?

Upvotes: 1

Views: 962

Answers (1)

Dmitry Zaytsev
Dmitry Zaytsev

Reputation: 23982

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?

Upvotes: 1

Related Questions