Skip to content

Commit 5dd9c8a

Browse files
committed
Android BarcodeReader: Correctly handle supported image formats on APIs < 23
1 parent 829a545 commit 5dd9c8a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

wrappers/android/zxingcpp/src/main/java/com/zxingcpp/BarcodeReader.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ import android.graphics.Bitmap
2020
import android.graphics.ImageFormat
2121
import android.graphics.Point
2222
import android.graphics.Rect
23+
import android.os.Build
2324
import androidx.camera.core.ImageProxy
2425
import java.lang.RuntimeException
2526
import java.nio.ByteBuffer
2627

2728
public class BarcodeReader {
29+
private val supportedYUVFormats: List<Int> =
30+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
31+
listOf(ImageFormat.YUV_420_888, ImageFormat.YUV_422_888, ImageFormat.YUV_444_888)
32+
} else {
33+
listOf(ImageFormat.YUV_420_888)
34+
}
35+
2836
init {
2937
System.loadLibrary("zxing_android")
3038
}
@@ -71,9 +79,8 @@ public class BarcodeReader {
7179
public var options : Options = Options()
7280

7381
public fun read(image: ImageProxy): Result? {
74-
val supportedYUVFormats = arrayOf(ImageFormat.YUV_420_888, ImageFormat.YUV_422_888, ImageFormat.YUV_444_888)
75-
if (image.format !in supportedYUVFormats) {
76-
error("invalid image format")
82+
check(image.format in supportedYUVFormats) {
83+
"Invalid image format: ${image.format}. Must be one of: $supportedYUVFormats"
7784
}
7885

7986
var result = Result()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy