在通过意图捕捉图像时,我遇到了问题。
我正在使用默认的意图代码来捕获图像。如下。
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PHOTO_CODE);
并在onActivityResult中接收它,如下所示。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if( TAKE_PHOTO_CODE==requestCode){
try {
Bundle extras = data.getExtras();
Bitmap mImageBitmap = (Bitmap) extras.get("data");
selectedImagePath = saveImageInfo(mImageBitmap, "image");
ExifInterface exif = new ExifInterface(selectedImagePath);
Toast.makeText(getBaseContext()," "+exif.getAttribute(ExifInterface.TAG_ORIENTATION), Toast.LENGTH_SHORT).show();
try {
showDialog(DIALOG_UPLOADING);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "No image selected.. ", Toast.LENGTH_SHORT).show();
}
}
}
我希望在这个onActivityResult方法中捕获的图像方向,我有搜索和关于它并找到了ExifInterface,但它对我不起作用,我在LG Optimus Android设备上测试,它总是为我返回0。 / p>
问题是在捕获图像后它被旋转。 任何解决方案?
答案 0 :(得分:0)
您可以使用该方法获得旋转,然后根据结果旋转图像 -
private int getDisplayRotation() {
int rotation = getWindowManager().getDefaultDisplay().getRotation();
switch (rotation) {
case Surface.ROTATION_0: return 0;
case Surface.ROTATION_90: return 90;
case Surface.ROTATION_180: return 180;
case Surface.ROTATION_270: return 270;
}
return 0;
}
为了摆脱许多设备特定的问题,我从头开始创建相机 您可以从https://github.com/vinsol/expense-tracker/tree/master/src/com/vinsol/expensetracker/cameraservice
获取代码然后使用以下方法调用它
private void startCamera() {
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
Intent camera = new Intent(this, Camera.class);
File file = new File("123.jpg");
Log.d("camera file path "+file.toString() );
camera.putExtra("FullSizeImagePath", file.toString());
startActivityForResult(camera, PICTURE_RESULT);
} else {
Toast.makeText(this, "sdcard not available", Toast.LENGTH_LONG).show();
}
}