从带有方向肖像的相机旋转的图像显示

时间:2013-04-19 12:56:34

标签: android camera rotation imageview android-gallery

我的问题是当我从图库中选择一些图像显示在图像视图中旋转时。我想在画廊中显示它。并且图像旋转的问题是因为该图像是从具有纵向方向的相机拍摄的。在图像视图中不显示以横向拍摄的图像。我怎么知道图像是从带有方向肖像或风景的相机拍摄的?或者,如果图像是从纵向模式拍摄的,我怎么能将它旋转回原始图像。任何想法都将被赞赏..谢谢提前.. 我到目前为止尝试过的代码如下所示。但它不能正常工作......

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        try {
            if (requestCode == Constants.GALLERY) {
                Log.e("Constants.gallery", "" + Constants.GALLERY);
                if (requestCode == 1) {
                    if (data != null && resultCode == RESULT_OK) {
                        Log.e("data", "data not null");
                        Uri images_uri = data.getData();
                        String[] image_path = { MediaStore.Images.Media.DATA };
                        Cursor c_image = getContentResolver().query(images_uri,
                                image_path, null, null, null);
                        c_image.moveToFirst();
                        int l = c_image.getColumnIndex(image_path[0]);
                        String image = c_image.getString(l);
                        c_image.close();
                        bmp_default = null;
                        if (bmp_default != null && !bmp_default.isRecycled()) {
                            bmp_default = null;
                        }
                        bmp_default = BitmapFactory.decodeFile(image);
Matrix matrix = new Matrix();

                        ExifInterface exifReader = new ExifInterface(image);

                        int orientation = exifReader.getAttributeInt(
                                ExifInterface.TAG_ORIENTATION, -1);

                        if (orientation == ExifInterface.ORIENTATION_NORMAL) {
                            Log.e("normal", "normal");
                            // Do nothing. The original image is fine.
                        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
                            Log.e("rotate_90", "rotate_90");
                            matrix.postRotate(90);

                        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
                            Log.e("rotate_180", "rotate_180");
                            matrix.postRotate(180);

                        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
                            Log.e("rotate_270", "rotate_270");
                            matrix.postRotate(270);

                        }
Bitmap bm = Bitmap.createBitmap(bmp_default, 0, 0, 100,
                                100, matrix, false);
                        getUpdatedImage();
                        image_view.removeAllViews();
                        view = new `ZoomRotateImage(ImageEditing.this, bm);`

                        image_view.addView(view);

                    } else {
                        Log.e("No pics", "No pics");
                    }

                }

            }

0 个答案:

没有答案