android / android/camera-samples

When use the method setTargetResolution, the metadata would be lost.

Open
#389 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
5.5k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

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.
-->
-
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintDimensionRatio="W, 3:4"
+ android:layout_height="0dp" />


\ 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.

Contributor guide

Open the contributing guide

Research direction

Start with CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt and reproduce the reported metadata lookup after using setTargetResolution. Trace the reported path through androidx.camera.core.internal.utils.ImageUtil#cropByteArray and compare the saved image metadata with the ExifInterface TAG_MODEL result. Done means identifying why metadata is lost and confirming that captured metadata is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.