【发布时间】:2020-07-18 20:30:08
【问题描述】:
我正在尝试使用 TensorImage.load() 加载用户使用相机应用拍摄的图片位图。当我传入位图时,出现此错误:
java.lang.IllegalArgumentException: Only supports loading ARGB_8888 bitmaps
这是我调用load 函数时的代码。首先,它以onActivityResult开头:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == CAMERA_REQUEST_CODE) {
if(Build.VERSION.SDK_INT < 28) {
val foodBitmap = MediaStore.Images.Media.getBitmap(this.contentResolver, Uri.fromFile(photoFile))
// pass this bitmap to the classifier
val predictions = foodClassifier.recognizeImage(foodBitmap, 0)
} else {
val source = ImageDecoder.createSource(this.contentResolver, Uri.fromFile(photoFile))
val foodBitmap = ImageDecoder.decodeBitmap(source)
// pass this bitmap to the classifier
val predictions = foodClassifier.recognizeImage(foodBitmap, 0)
}
}
}
在recognizeImage 函数中,我调用了一个名为inputImageBuffer 的变量,它的类型为TensorImage。我调用load 函数并传递bitmap。这是应用程序崩溃的地方。谁能告诉我如何解决这个问题?
【问题讨论】:
标签: android image android-studio tensorflow kotlin