我想启动原生Android相机并将拍摄的图像保存在指定位置,但是当我这样做并且我稍后尝试到达照片时,保存的图像会自动旋转90度。我正在使用LG手机来运行该程序。我已经尝试过我在这里找到的解决方案,但它们没有用。我在这里为你提供代码......请纠正我或给我一个新的解决方案。 非常感谢你
private void cameraIntent() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("photo", true);
intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
startActivityForResult(intent, REQUEST_CAMERA);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQUEST_CAMERA)
onCaptureImageResult(data);
}
}
private void onCaptureImageResult(Intent data) {
ByteArrayOutputStream bytes = null;
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
File destination = new File(getExternalStorageDirectory(),
File.separator + "profile.jpg");
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String address = getExternalStorageDirectory().getAbsolutePath();
ExifInterface exif = null;
try {
if(destination.exists()) {
exif = new ExifInterface(address+File.separator+"profile.jpg");
Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
}
} catch (IOException e) {
e.printStackTrace();
}
if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){
thumbnail= rotate(thumbnail, 90);
}else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){
thumbnail= rotate(thumbnail, 270);
}else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){
thumbnail= rotate(thumbnail, 270);
}
resized = Bitmap.createScaledBitmap(thumbnail, navUserImage.getWidth(), navUserImage.getHeight(), true);
navUserImage.setImageBitmap(resized);
}