Closed ghulammustafahaider closed 6 years ago
how did you fix this? When i code to use the front it stas using the back cam. When i delete the code to use the back cam and program to use the front it just closes itself in error.
I am able to open front camera but detection not working i changed code in opencamera method
private void openCamera(final int width, final int height) { setUpCameraOutputs(width, height); configureTransform(width, height); final Activity activity = getActivity(); final CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } if (ActivityCompat.checkSelfPermission(this.getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { Timber.tag(TAG).w("checkSelfPermission CAMERA"); } // manager.openCamera(cameraId, stateCallback, backgroundHandler); manager.openCamera("1", stateCallback, backgroundHandler); Timber.tag(TAG).d("open Camera"); } catch (final CameraAccessException e) { Timber.tag(TAG).e("Exception!", e); } catch (final InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening.", e); } }
please modify your OnGetImageListener class
private void drawResizedBitmap(final Bitmap src, final Bitmap dst) {
Display getOrient = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
Point point = new Point();
getOrient.getSize(point);
int screen_width = point.x;
int screen_height = point.y;
Log.d(TAG, String.format("screen size (%d,%d)", screen_width, screen_height));
if (screen_width < screen_height) {
orientation = Configuration.ORIENTATION_PORTRAIT;
Toast.makeText(mContext, "90", Toast.LENGTH_SHORT).show();
mScreenRotation = 270;
} else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
Toast.makeText(mContext, "0", Toast.LENGTH_SHORT).show();
mScreenRotation = 90;
}
Assert.assertEquals(dst.getWidth(), dst.getHeight());
final float minDim = Math.min(src.getWidth(), src.getHeight());
final Matrix matrix = new Matrix();
// We only want the center square out of the original rectangle.
final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
matrix.preTranslate(translateX, translateY);
final float scaleFactor = dst.getHeight() / minDim;
matrix.postScale(scaleFactor, scaleFactor);
// Rotate around the center if necessary.
if (mScreenRotation != 0) {
matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
matrix.postRotate(mScreenRotation);
matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
}
final Canvas canvas = new Canvas(dst);
canvas.drawBitmap(src, matrix, null);
}
How to Open Front Face Camera when ever i open camera its open back camera and in code the code shows the front camera code....