【发布时间】:2016-10-31 23:27:00
【问题描述】:
我正在尝试将默认相机与 Intent 一起用于图像和视频捕获。 当我转向前置摄像头并捕捉图像或视频时,预览(捕捉的图像或视频)被反转。所以现在我想把 preScale 放在 frontCamera 中。但是不知道在哪里可以找到默认相机中的相机 ID。!!
注意:这不是自定义相机。!!
问题是:从前置摄像头获取的图像是镜像。看看有没有问题?我没有得到!谢谢
即使存储在 SDCard 中的图像也是镜像!现在如何 preScale 或任何其他想法来纠正 iT?
帮助!
photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
captureImage();
}
});
CatureImage 方法
private void captureImage() {
Context context = this;
PackageManager packageManager = context.getPackageManager();
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) == false
&& packageManager
.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY) == false) {
Toast.makeText(CameraRolling2.this, "camera not available'",
Toast.LENGTH_SHORT).show();
return;
}
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent
.resolveActivity(CameraRolling2.this.getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
Toast.makeText(CameraRolling2.this, "Error connecting camera",
Toast.LENGTH_SHORT).show();
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent,
CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
showImg.setImageBitmap(null);
}
}
}
@SuppressLint("SimpleDateFormat")
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName, ".jpg", storageDir);
mCurrentPhotoPath = image.getAbsolutePath();
Log.v("createImageFile", "" + mCurrentPhotoPath);
return image;
}
和我的活动结果
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE
&& resultCode == Activity.RESULT_OK) {
File imgFile = new File(mCurrentPhotoPath);
if (imgFile.exists()) {
BitmapFactory.Options bitmap_options = new BitmapFactory.Options();
bitmap_options.inSampleSize = 4;
bitmap_options.outHeight = 200;
bitmap_options.outWidth = 200;
Bitmap myBitmap = BitmapFactory.decodeFile(
imgFile.getAbsolutePath(), bitmap_options);
showImg.setImageBitmap(myBitmap);
if (showImg.getDrawable() == null) {
Log.e("IMAGEVIEW", "NULL IMAGE");
imageflag = false;
} else {
Log.e("IMAGEVIEW", "IMAGE VIEW UPDATED");
imageflag = true;
}
}
}
if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(CameraRolling2.this, "Camera option canceled",
Toast.LENGTH_SHORT).show();
imageflag = false;
}
【问题讨论】:
标签: android camera android-camera android-camera-intent