这就是我所做的。我将像素数组转换为位图并翻转它。我注意到我还必须旋转我的图像。如果你需要这样做,你可以使用下面的 rotateBitmap 方法。我在翻转它之前旋转了它。由于我的应用程序使用了两个摄像头,我首先检查它是否使用前置摄像头。
public Bitmap flip(Bitmap d)
{
Matrix m = new Matrix();
m.preScale(-1, 1);
Bitmap dst = Bitmap.createBitmap(d, 0, 0, d.getWidth(), d.getHeight(), m, false);
dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
return dst;
}
public Bitmap rotateBitmap(Bitmap source, float angle)
{
//Rotates Bitmap
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
所以它看起来像这样。
if(orienation == Orienation.SELFIE)
{
bMap = rotateBitmap(bMap, 270);
bMap = flip(bMap);
}
这些只是我在应用程序中使用的一些自定义字段。我想你明白了,可以随心所欲地迎合它。
private Camera.PictureCallback mPicture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap bMap = BitmapFactory.decodeByteArray(data, 0, data.length);
if (currentCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT) {
frontFacing = true;
}
}
};
您可以在 PictureCallback 中创建位图。只需将像素数组转换为位图。如果您在应用程序中同时使用这两个摄像头,您可以检查是否像我在上面的示例中那样使用了前面的摄像头。