Java 来自动作的图像\u图像\u捕获旋转
我只是想从手机的摄像头中获取图像。令人惊讶的是,它返回旋转。我在互联网上搜寻修复程序,发现了许多使用ExiFinInterface的解决方案,但它只是有时有效。它的方向似乎是随机错误的,因为我只是重新编译并看到不同的结果。我发现一些人说这是班级本身被窃听的错误 我发现其他解决方案需要两个额外的库和更多的java文件来完成这项工作,但这似乎很荒谬(我正在避免额外的包)。首先,为什么图像会被旋转(在存储中它们非常好),解决这个问题有多困难?另外-旋转图像视图也可以(看起来比创建旋转图像容易得多),但我需要知道旋转视图的角度 编辑----我意识到,如果使用后摄像头,图像始终从拍摄方向顺时针旋转270度(在意图内),如果使用前摄像头,则旋转90度。因此,我只需要一种方法来找出这个方向 此处所称意图:Java 来自动作的图像\u图像\u捕获旋转,java,android,image,Java,Android,Image,我只是想从手机的摄像头中获取图像。令人惊讶的是,它返回旋转。我在互联网上搜寻修复程序,发现了许多使用ExiFinInterface的解决方案,但它只是有时有效。它的方向似乎是随机错误的,因为我只是重新编译并看到不同的结果。我发现一些人说这是班级本身被窃听的错误 我发现其他解决方案需要两个额外的库和更多的java文件来完成这项工作,但这似乎很荒谬(我正在避免额外的包)。首先,为什么图像会被旋转(在存储中它们非常好),解决这个问题有多困难?另外-旋转图像视图也可以(看起来比创建旋转图像容易得多),但
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = setUpPhotoFile();
mCurrentPhotoPath = photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
} catch (IOException ex) {
// Error occurred while creating the File
photoFile = null;
mCurrentPhotoPath = null;
}
// Continue only if the File was successfully created
if (photoFile != null) {
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
} else {
Toast noStorage = Toast.makeText(this, "Cannot access mounted storage.", Toast.LENGTH_SHORT);
noStorage.show();
}
}
}
此处创建的位图:
private void setPic() {
/* Get the size of the ImageView */
int targetW = mImageView.getWidth();
int targetH = mImageView.getHeight();
/* Get the size of the image */
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
/* Figure out which way needs to be reduced less */
int scale = 1;
if (photoH > targetH|| photoW > targetW) {
scale = Math.max(
(int)Math.pow(2, (int) Math.ceil(Math.log(targetW /
(double) photoW)) / Math.log(0.5)),
(int)Math.pow(2, (int) Math.ceil(Math.log(targetH /
(double) photoH)) / Math.log(0.5)));
;
}
/* Set bitmap options to scale the image decode target */
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scale;
/* Decode the JPEG file into a Bitmap */
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
/*-----------How should I rotate bitmap/mImageView to correct orientation?*/
/* Associate the Bitmap to the ImageView */
mImageView.setImageBitmap(bitmap);
mImageView.setVisibility(View.VISIBLE);
}
我找到的最佳解决方案是: 我发布链接是因为我不想要所有的信用 Sami Eltamawy编写了一个函数,可以在需要旋转图像时旋转图像 我尝试了这段代码,正在我的设备上工作,图像被旋转了