Skip to content Skip to sidebar Skip to footer

Android Emulator Camera - Webcam Orientation

I am using my Mac webcam to simulate an Android front-camera in the emulator. Unfortunately the camera seems in landscape orientation - screenshot, even though the emulator is in p

Solution 1:

Ultimately I solved this by detecting if I'm running in an emulator:

publicstatic 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:

Matrixmatrix=newMatrix();
WindowManagerwindowManager= (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Displaydisplay= windowManager.getDefaultDisplay();
PointdisplaySize=newPoint();
display.getRealSize(size);
RectFviewRect=newRectF(0, 0, mCameraPreview.getWidth(), mCameraPreview.getHeight());
floatcenterX= viewRect.centerX();
floatcenterY= viewRect.centerY();
floatscale= (float) mCameraPreview.getWidth() / (float) displaySize.x;
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(270, centerX, centerY);
mCameraPreview.setTransform(matrix);

Solution 2:

I enabled auto-rotation on emulator and then turned emulator to landscaped mode, and it worked.

Post a Comment for "Android Emulator Camera - Webcam Orientation"