我正在使用 blow post 来处理相机 API,并将相机翻转到后/前。 Fliping the Front Camera to Back Camera in Button Click using android
默认情况下,在三星设备中,它会横向打开相机预览,但
camera.setDisplayOrientation(90);
通过此代码,我能够以纵向方式打开相机预览。但是当我保存图像时,它会自动将其保存为横向。
通过使用这个方法
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(rotatedBitmap,
curntViewWidth, curntViewHeight, true);
处理速度变慢。有没有人有任何其他方式可以使相机预览、捕获和保存图像方向相同..
我们有没有像这个应用一样可以打开相机并设置特定尺寸图像的库 https://play.google.com/store/apps/details?id=com.tinypiece.android.mlc
最佳答案
来自 Camera.Parameters#setRotation()
的文档:
If applications want to rotate the picture to match the orientation of what users see, apps should use OrientationEventListener and Camera.CameraInfo
public void onOrientationChanged(int orientation) {
if (orientation == ORIENTATION_UNKNOWN) return;
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
orientation = (orientation + 45) / 90 * 90;
int rotation = 0;
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}
mParameters.setRotation(rotation);
}
OrientationEventListener
是一个包含 onOrientationChanged()
的抽象类。此方法将从系统接收方向更改。这是一种可能的实现方式:
OrientationEventListener listener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int i) {
//Code from above goes here.
}
};
listener.enable();
关于android - Camera API 拍摄的图像自动横向保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20844948/