2017-02-17 47 views
1

我在三星设备上的图像有问题 每次我拍一张照片的垂直形式,但是当它调用图像库时,教室 垂直 它用ExifInterface类我无法找到导致imageView中的照片方向与三星手机

我每次拍照我打电话给我的类PreviewImage这是我显示出图像 后来我有带我到指定的个人资料照片我有这个方法的按钮onActivityResult

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) { 
     try { 
      ExifInterface exifInterface = new ExifInterface(photoFile.getAbsolutePath()); 
      int exif = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 
      switch (exif) { 
       case ExifInterface.ORIENTATION_ROTATE_90: 
        orientation = 90; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_180: 
        orientation = 180; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_270: 
        orientation = 270; 
        break; 
      } 
     } catch (Exception e) { 
      Log.d("tmessages", e.toString()); 
     } 
     Intent intent = new Intent(this, PhotoViewer.class); 
     intent.putExtra(EXTRA_PHOTO_PATH, photoFile.getAbsolutePath()); 
     intent.putExtra(EXTRA_PHOTO_ORIENTATION, orientation); 
     intent.putExtra(EXTRA_PHOTO_EDIT, false); 
     startActivityForResult(intent, 10); 

    } 

这是我PhotoViewer类

private void sendPicture() { 
     Intent returnIntent = new Intent(); 
     returnIntent.putExtra("photoDescription", photoDescription.getText().toString()); 
     returnIntent.putExtra("photoPath", localPath); 
     returnIntent.putExtra("orientation", orientation); 
     setResult(Activity.RESULT_OK, returnIntent); 
     finish(); 
    } 

一旦拍摄完成返回我的个人资料类从那里它被称为

else if (requestCode == 10 && resultCode == Activity.RESULT_OK) { 
     if (photoFile != null&&LoginController.getInstance().xmppConnection.isConnected()) { 
      byte[] photo = AndroidUtilities 
        .createProfileImage(photoFile.getAbsolutePath()); 
      ProfileManager.getInstance().publishPhoto(photo); 
      Bitmap decodedByte = BitmapFactory.decodeByteArray(photo, 0, photo.length); 
      avatar.setImageBitmap(decodedByte); 
     }else{ 
      Toast.makeText(this,R.string.LabelProfilePhotoFailed, Toast.LENGTH_SHORT).show(); 
     } 
    } 

的onActivityResult方法我怎样才能使形象展示我垂直在个人资料照片?

+0

能否请您使用短语,如“画像”和而不是“垂直”景观'。你的问题不清楚。你能否请你审查并改变它,因为你说你想要垂直显示图像,你的评论说它已经显示垂直。 –

回答

0

你已经完成了一半的工作!只需使用您之前计算的方向:

else if (requestCode == 10 && resultCode == Activity.RESULT_OK) { 
    if (photoFile != null&&LoginController.getInstance().xmppConnection.isConnected()) { 
     byte[] photo = AndroidUtilities 
       .createProfileImage(photoFile.getAbsolutePath()); 
     ProfileManager.getInstance().publishPhoto(photo); 
     Bitmap decodedByte = BitmapFactory.decodeByteArray(photo, 0, photo.length); 
->  decodedByte = rotate(decodedByte, orientation); 
     avatar.setImageBitmap(decodedByte); 
    }else{ 
     Toast.makeText(this,R.string.LabelProfilePhotoFailed, Toast.LENGTH_SHORT).show(); 
    } 
} 

方向 = getIntent()getExtras()getInt(EXTRA_PHOTO_ORIENTATION)。

private static Bitmap rotate(Bitmap bm, int rotation) { 
    if (rotation != 0) { 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(rotation); 
     Bitmap bmOut = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); 
     return bmOut; 
    } 
    return bm; 
} 
+0

你好朋友首先感谢帮助,创建了方法来打开 私人位图旋转(位图decodedByte,int方向)orientation = getIntent()。getExtras()。getInt(EXTRA_PHOTO_ORIENTATION); return decodedByte; } 但是,我没有得到正确的旋转,增长,我不断失败? – Devix

+0

朋友真的很感谢,还有一个问题呢?如果我拍摄水平照片并且照片保持垂直,在任何时候如何控制?感谢您向我提供垂直照片的方法,而这正是我想要的,但是做一个以横向模式拍照的测试,我打破了这个图像,您是否知道这可能是什么?事先非常感谢你。 – Devix

+0

尝试添加以下行:getContentResolver()。notifyChange(photoFile,null);在使用ExifInterface之前exifInterface = new ExifInterface(photoFile.getAbsolutePath());如果我的回答对你有帮助,你可以请upvote或接受我的回答:)? –