@carviz/capacitor-camera-preview 8.0.2 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -104,46 +104,55 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback, TextureV
|
|
|
104
104
|
if (mCamera == null) {
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
107
|
+
try {
|
|
108
|
+
Camera.CameraInfo info = new Camera.CameraInfo();
|
|
109
|
+
int rotation = ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRotation();
|
|
110
|
+
int degrees = 0;
|
|
111
|
+
DisplayMetrics dm = new DisplayMetrics();
|
|
112
|
+
|
|
113
|
+
Camera.getCameraInfo(cameraId, info);
|
|
114
|
+
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
115
|
+
|
|
116
|
+
switch (rotation) {
|
|
117
|
+
case Surface.ROTATION_0:
|
|
118
|
+
degrees = 0;
|
|
119
|
+
break;
|
|
120
|
+
case Surface.ROTATION_90:
|
|
121
|
+
degrees = 90;
|
|
122
|
+
break;
|
|
123
|
+
case Surface.ROTATION_180:
|
|
124
|
+
degrees = 180;
|
|
125
|
+
break;
|
|
126
|
+
case Surface.ROTATION_270:
|
|
127
|
+
degrees = 270;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
facing = info.facing;
|
|
131
|
+
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
|
132
|
+
displayOrientation = (info.orientation + degrees) % 360;
|
|
133
|
+
displayOrientation = (360 - displayOrientation) % 360;
|
|
134
|
+
} else {
|
|
135
|
+
displayOrientation = (info.orientation - degrees + 360) % 360;
|
|
136
|
+
}
|
|
136
137
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
Log.d(TAG, "screen is rotated " + degrees + "deg from natural");
|
|
139
|
+
Log.d(
|
|
140
|
+
TAG,
|
|
141
|
+
(info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ? "front" : "back") +
|
|
142
|
+
" camera is oriented -" +
|
|
143
|
+
info.orientation +
|
|
144
|
+
"deg from natural"
|
|
145
|
+
);
|
|
146
|
+
Log.d(TAG, "need to rotate preview " + displayOrientation + "deg");
|
|
147
|
+
mCamera.setDisplayOrientation(displayOrientation);
|
|
148
|
+
} catch (RuntimeException e) {
|
|
149
|
+
// The Camera1 handle can be released / mid-teardown / not yet fully opened when an
|
|
150
|
+
// orientation or configuration change arrives (screen-orientation lock/unlock, device
|
|
151
|
+
// rotation, or leaving the camera screen). In that state Camera.setDisplayOrientation()
|
|
152
|
+
// throws "set display orientation failed". Swallow it: the preview is either going away,
|
|
153
|
+
// or the orientation is re-applied by startCamera() on the next valid surface pass.
|
|
154
|
+
Log.e(TAG, "setCameraDisplayOrientation failed; camera in invalid state", e);
|
|
155
|
+
}
|
|
147
156
|
}
|
|
148
157
|
|
|
149
158
|
public void switchCamera(Camera camera, int cameraId) {
|
|
@@ -331,7 +340,10 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback, TextureV
|
|
|
331
340
|
Camera.Parameters parameters = mCamera.getParameters();
|
|
332
341
|
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
333
342
|
requestLayout();
|
|
334
|
-
//
|
|
343
|
+
// Re-apply orientation on a camera just confirmed alive by getParameters() above. This
|
|
344
|
+
// self-heals if setCameraDisplayOrientation() was swallowed during a config-change race:
|
|
345
|
+
// a rotation resizes the surface, so surfaceChanged -> startCamera() runs here.
|
|
346
|
+
setCameraDisplayOrientation();
|
|
335
347
|
mCamera.setParameters(parameters);
|
|
336
348
|
mCamera.startPreview();
|
|
337
349
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carviz/capacitor-camera-preview",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.3",
|
|
4
4
|
"description": "Fork of the capacitor-community/camera-preview plugin focusing on high resolution photos without bloating up the code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|