Android emulator camera - webcam orientation

I am using my Mac webcam to simulate an Android front camera in an emulator. Unfortunately, the camera looks in landscape orientation - screenshot , although the emulator is in portrait orientation.

Please note that the camera behaves correctly on a real device (i.e. it has a portrait orientation).

My emulator config: Nexus 5X, Android Nougat 7.1.1, API Level 25, Startup Orientation: portrait, front camera: webcam0, back-camera: Emulated

How can I use my webcam with the correct orientation?

+3


source to share


1 answer


I ended up solving it by discovering if I was running in the emulator:

public static boolean isEmulator() {
  return Build.FINGERPRINT.startsWith("generic")
    || Build.FINGERPRINT.startsWith("unknown")
    || Build.MODEL.contains("google_sdk")
    || Build.MODEL.contains("Emulator")
    || Build.MODEL.contains("Android SDK built for x86")
    || Build.MANUFACTURER.contains("Genymotion")
    || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
    || "google_sdk".equals(Build.PRODUCT);
}

      



And then applying a transform to the preview texture:

Matrix matrix = new Matrix();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point displaySize = new Point();
display.getRealSize(size);
RectF viewRect = new RectF(0, 0, mCameraPreview.getWidth(), mCameraPreview.getHeight());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
float scale = (float) mCameraPreview.getWidth() / (float) displaySize.x;
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(270, centerX, centerY);
mCameraPreview.setTransform(matrix);

      

0


source







All Articles