【发布时间】:2015-04-21 12:34:23
【问题描述】:
我知道我可以设置boolean flag while opening front Camera。如果标志为真,则表示前置摄像头已打开。
但是有没有办法使用 Android API 来知道哪个相机现在是打开的?正面或背面。
public int getFrontCameraId() {
CameraInfo ci = new CameraInfo();
for (int i = 0 ; i < Camera.getNumberOfCameras(); i++) {
Camera.getCameraInfo(i, ci);
if (ci.facing == CameraInfo.CAMERA_FACING_FRONT) return i;
}
return -1; // No front-facing camera found
}
当我打开前置摄像头时,摄像头预览正在反转(倒置)。所以我必须添加一个检查哪个相机是打开的if FrontCamera is opened then matrix = 270. otherwise matrix =90.
onPreviewFrame(byte abyte0[] , Camera camera)
int[] rgbData = YuvUtils.decodeGreyscale(abyte0, mWidth,mHeight);
editedBitmap.setPixels(rgbData, 0, widthPreview, 0, 0, widthPreview, heightPreview);
finalBitmap = Bitmap.createBitmap(editedBitmap, 0, 0, widthPreview, heightPreview, matrix, true);
【问题讨论】: