J'utilise l'appareil photo dans mon application pour capturer l'image, lorsque vous passez à la caméra frontale, l'image est mirrorrd. J'utilise ce code pour prendre une photo (tourner et compenser le miroir) avec ce code Retour caméra est OK (sans miroir et tourner)! mais le résultat de la caméra avant similaire cette image:Orientation image image après utilisation Caméra avant ou arrière
cette méthode pour obtenir ID caméra avant: (j'utilise CameraInfo pour obtenir id caméra avant et envoyer id pour résultat l'activité)
public int getFrontFacingCameraId() {
int numCameras = getNumberOfCameras();
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
for (int cameraId = 0; cameraId < numCameras; cameraId++) {
Camera.getCameraInfo(cameraId, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
return cameraId;
}
}
return 0;
}
ce code pour la rotation: (matrice d'utilisation)
private Bitmap rotateImage(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
return source;
}
}
et cette utilisation du code dans l'activité resu lt:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case PICTURE_RESULT:
if (resultCode == Activity.RESULT_OK) {
try {
Bitmap thumbnail = MediaStore.Images.Media.getBitmap(getContentResolver(), IMG_URI);
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0:
degrees = 90;
break;
case Surface.ROTATION_90:
degrees = 180;
break;
case Surface.ROTATION_180:
degrees = 270;
break;
case Surface.ROTATION_270:
degrees = 360;
break;
}
int displayOrientation;
if (cameraInfo.facing == getFrontFacingCameraId()) {
displayOrientation = (cameraInfo.orientation + degrees) % 360;
displayOrientation = (360 - displayOrientation) % 360;
} else {
displayOrientation = (cameraInfo.orientation - degrees + 360) % 360;
}
USER_CIRCLE_PHOTO.setImageBitmap(Bitmap.createScaledBitmap(rotateImage(thumbnail, displayOrientation), 480, 800, false));
getContentResolver().delete(IMG_URI, null, null);
} catch (Exception e) {
displayToast(this, "خطای گرفتن عکس:" + "\n" + e.toString());
}
}
}
}
Comment puis-je résoudre le problème Merci
et quand le changement à ceci:
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
retour et pour la caméra pas OK!
ne fonctionne pas pour moi! –