我試圖使用默認相機與意圖爲圖像和視頻捕獲。 當我轉向前置攝像頭並拍攝圖像或視頻預覽(拍攝的圖像或視頻)時,會發生顛倒。所以現在我想把preScale在frontCamera。但不知道在哪裏可以找到相機ID在默認相機。如何檢查前置攝像頭ID?捕獲的圖像也是來自前置攝像頭的鏡像。
注意:這不是自定義相機。
問題是:從前置攝像頭獲取的圖像獲取圖像是鏡像。看看有沒有問題?我沒有得到! Thx
即使在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;
}
倒轉意味着變得鏡像 –
@HarshBhavsar:無論如何,你無法強迫第三方相機應用程序使用特定的硬件攝像頭(前置/後置/等)。您無法檢測使用了哪臺相機。您無法確定相機應用內的用戶是否翻轉了圖像,裁剪了它,否則會影響圖像的結果。 – CommonsWare
@CommomsWare編輯的問題!我希望你找到一些東西! –