在人像模式下拍摄后旋转照片

时间:2015-07-30 00:59:05

标签: android android-camera android-imageview

我正在尝试拍摄捕获的图像并显示到“活动”。设置图像后,它会向右旋转90度。我不确定我做错了什么。我使用MediaStore.ACTION_IMAGE_CAPTURE捕获图像并将其保存并使用URI进行设置。这是代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_selectusername);

    confirm = (Button) findViewById(R.id.confirm_select);
    confirm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            takePhoto();

        }
    });

}

private void takePhoto() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File photo = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

    //This is for photo editing purposes
    inputURI = Uri.fromFile(photo);
    outputURI = Uri.fromFile(new File(getCacheDir(), photoname));

    //Cropping, Resizing, etc. takes place

    startActivityForResult(intent, TAKE_PICTURE);


}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent result) {
    super.onActivityResult(requestCode, resultCode, result);
    if(requestCode == TAKE_PICTURE && resultCode == RESULT_OK){
        ImageView imageView = (ImageView) findViewById(R.id.profilepicture_select);

        imageView.setImageURI(outputURI);

    }else{
        Log.d("TEST", "Something went wrong!");
    }
}

我可以展示更多代码并在必要时进行澄清。感谢所有帮助!

1 个答案:

答案 0 :(得分:0)

您的代码看起来很好。这可能是该设备相机的问题。这是Galaxy S4的一个已知问题。某些设备输出奇怪的exif数据,导致图像在显示时关闭。你是如何解决的?

以下是您的领导: Android camera/picture orientation issues with Samsung Galaxy S3, S4, S5