camera-samples
camera-samples copied to clipboard
When use the method setTargetResolution, the metadata would be lost.
Use the code below to query metadata.
val model = ExifInterface(savedUri.toFile()).getAttribute(ExifInterface.TAG_MODEL)
Log.d(TAG, "Photo capture succeeded: model ==> $model")
Here is patch.
The target branch hash is : 852767fd 2021/5/27 at 21:32
Index: CameraXBasic/app/src/main/AndroidManifest.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- CameraXBasic/app/src/main/AndroidManifest.xml (revision 852767fddd25b0f33e117d811bd5cdb6694b8904)
+++ CameraXBasic/app/src/main/AndroidManifest.xml (date 1624348335530)
@@ -41,7 +41,7 @@
android:clearTaskOnLaunch="true"
android:theme="@style/AppTheme"
android:icon="@mipmap/ic_launcher"
- android:screenOrientation="fullUser"
+ android:screenOrientation="portrait"
android:rotationAnimation="seamless"
android:resizeableActivity="true"
android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize"
Index: CameraXBasic/app/src/main/res/layout/fragment_camera.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- CameraXBasic/app/src/main/res/layout/fragment_camera.xml (revision 852767fddd25b0f33e117d811bd5cdb6694b8904)
+++ CameraXBasic/app/src/main/res/layout/fragment_camera.xml (date 1624354469810)
@@ -14,8 +14,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<androidx.constraintlayout.widget.ConstraintLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/camera_container"
android:background="@android:color/black"
android:layout_width="match_parent"
@@ -24,6 +24,8 @@
<androidx.camera.view.PreviewView
android:id="@+id/view_finder"
android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintDimensionRatio="W, 3:4"
+ android:layout_height="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Index: CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt (revision 852767fddd25b0f33e117d811bd5cdb6694b8904)
+++ CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt (date 1624355800525)
@@ -30,6 +30,7 @@
import android.os.Build
import android.os.Bundle
import android.util.Log
+import android.util.Size
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
@@ -52,6 +53,7 @@
import androidx.core.content.ContextCompat
import androidx.core.net.toFile
import androidx.core.view.setPadding
+import androidx.exifinterface.media.ExifInterface
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
@@ -290,7 +292,7 @@
// Preview
preview = Preview.Builder()
// We request aspect ratio but no resolution
- .setTargetAspectRatio(screenAspectRatio)
+ .setTargetResolution(Size(3648, 2736))
// Set initial target rotation
.setTargetRotation(rotation)
.build()
@@ -300,7 +302,7 @@
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
// We request aspect ratio but no resolution to match preview config, but letting
// CameraX optimize for whatever specific resolution best fits our use cases
- .setTargetAspectRatio(screenAspectRatio)
+ .setTargetResolution(Size(3648, 2736))
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
.setTargetRotation(rotation)
@@ -309,7 +311,7 @@
// ImageAnalysis
imageAnalyzer = ImageAnalysis.Builder()
// We request aspect ratio but no resolution
- .setTargetAspectRatio(screenAspectRatio)
+ .setTargetResolution(Size(3648, 2736))
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
.setTargetRotation(rotation)
@@ -411,6 +413,9 @@
val savedUri = output.savedUri ?: Uri.fromFile(photoFile)
Log.d(TAG, "Photo capture succeeded: $savedUri")
+ val model = ExifInterface(savedUri.toFile()).getAttribute(ExifInterface.TAG_MODEL)
+ Log.d(TAG, "Photo capture succeeded: model ==> $model")
+
// We can only change the foreground Drawable using API level 23+ API
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Update the gallery thumbnail with latest picture taken
I found that the metadata lost after androidx.camera.core.internal.utils.ImageUtil#cropByteArray called.