简体   繁体   English

来自图库意图的Android图片

[英]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? 好像是通过旋转的Android图库查看的?

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

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 selectedImageUri-这是从意图画廊返回的数据

bmO -bitmap created by selectedImageUri bmO-由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. 因为Android Gallery应用程序可以帮您实现。 So, you need to implement such thing by yourself 所以,你需要自己实现

Don't worry - it's easy: How to crop and rotate image programmatically in android? 不用担心-这很简单: 如何在Android中以编程方式裁剪和旋转图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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