Skip to content

Commit

Permalink
Update app
Browse files Browse the repository at this point in the history
  • Loading branch information
jenly1314 committed Dec 31, 2023
1 parent fe79be0 commit 0a6214d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
18 changes: 2 additions & 16 deletions app/src/main/java/com/king/mlkit/vision/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ package com.king.mlkit.vision.app

import android.Manifest
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.ImageDecoder
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import android.view.View
Expand Down Expand Up @@ -119,8 +116,9 @@ class MainActivity : AppCompatActivity() {
).addOnSuccessListener(this) { result ->
if (result.isNotEmpty()) {
val buffer = StringBuilder()
val srcBitmap = MediaStore.Images.Media.getBitmap(contentResolver, it)
// 成功;在图片上框出结果
val bitmap = it.getBitmap().drawRect { canvas, paint ->
val bitmap = srcBitmap.drawRect { canvas, paint ->
for ((index, barcode) in result.withIndex()) {
buffer.append("[$index] ").append(barcode.displayValue)
.append("\n")
Expand Down Expand Up @@ -153,18 +151,6 @@ class MainActivity : AppCompatActivity() {
}
}

/**
* 根据Uri获取对应的图片
*/
private fun Uri.getBitmap(): Bitmap {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val source = ImageDecoder.createSource(contentResolver, this)
ImageDecoder.decodeBitmap(source)
} else {
MediaStore.Images.Media.getBitmap(contentResolver, this)
}
}

private fun startActivity(cls: Class<*>) {
startActivity(Intent(this, cls))
}
Expand Down

0 comments on commit 0a6214d

Please sign in to comment.