旋转

2015-06-08 49 views
1
  Uri selectedImage = outputFileUri; 
        InputStream imageStream =getContentResolver().openInputStream(selectedImage); 
        try 
        { 
         BitmapFactory.Options bounds = new BitmapFactory.Options(); 
         bounds.inJustDecodeBounds=true;              BitmapFactory.decodeFile(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this), bounds); 
         BitmapFactory.Options opts = new BitmapFactory.Options(); 
         Bitmap bm = BitmapFactory.decodeFile(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this), opts); 
         ExifInterface exif = new ExifInterface(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this)); 
         String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION); 
         int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL; 
         int rotationAngle = 0; 
         if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90; 
         if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180; 
         if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270; 
         Matrix matrix = new Matrix(); 
         matrix.setRotate(rotationAngle, (float) bm.getWidth()/2, (float) bm.getHeight()/2); 
         Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true); 
         bitmap2 = rotatedBitmap;//BitmapFactory.decodeStream(imageStream); 
        } 
        catch(Exception ef) 
        { 
         bitmap2 = BitmapFactory.decodeStream(imageStream); 
        } 

很简单,当我的Android应用我在纵向模式下打开camera..and拍摄照片。我得到的图片回转。我该如何解决这个问题?我做过的上述工作没有任何影响。旋转

回答

0

尝试更换此代码

matrix.setRotate(rotationAngle, (float) bm.getWidth()/2, (float) bm.getHeight()/2); 
Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true); 

与此

matrix.postRotate(rotationAngle); 
Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); 
+0

它没有工作 – user3278732

+0

你登录你的代码?它是否成功地完成了整个过程?我想不出还会有什么。我有一块非常类似的代码为我工作。 – funkomatic

+0

rotationAngle始终为0 – user3278732