在我下面的code,我想使用本机摄像头拍摄照片并上传到服务器,但是当我把它当作肖像,并查看它画廊景观,这意味着,它旋转到90度。请帮助: -
In my code below, I am trying to take photo using native camera and upload to server but when I take it as portrait and view it in gallery as landscape which means, its rotated to 90 degree. Pls help :-
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQUEST_CAMERA) {
handleCameraPhoto();
}
private void handleCameraPhoto() {
Intent mediaScanIntent = new Intent(
"android.intent.action.MEDIA_SCANNER_SCAN_FILE");
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
getActivity().sendBroadcast(mediaScanIntent);
}
我如何可以旋转图像保存到SD卡之前?
How can I rotate the image before saving to SD card?
推荐答案
我也遇到这样的问题,同时显示在列表视图中的图像。但使用EXIF数据我能得到周围的工作在正确的方向设置的图像。
I also faced this kind of problem while showing the images in listview. But using the EXIF data I was able to get a work around to set the images in proper orientation.
这是是用于显示位图对象是prepared:
This is were the bitmap object for display is prepared :
Matrix matrix = new Matrix();
matrix.postRotate(getImageOrientation(url));
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
这是使用在上述code二号线的方法,旋转图像取向研究。
This is the method used, in the 2nd line of above code, to rotate the images orientaion.
public static int getImageOrientation(String imagePath){
int rotate = 0;
try {
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return rotate;
}
这未必是precise回答你的问题,它为我工作,并希望这将是对您有用。
This may not be the precise answer to your question, it worked for me and hope it will be useful for you.
相关推荐
最新文章