简体   繁体   中英

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM