I'm trying to use TensorImage.load()
to load a bitmap of picture the user took with the camera app. When I pass in the bitmap I get this error:
java.lang.IllegalArgumentException: Only supports loading ARGB_8888 bitmaps
This is my code for when I call the load
function. First, it starts with the 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)
}
}
}
In the recognizeImage
function, I call a variable named inputImageBuffer
which is of type TensorImage
. I call the load
function and pass the bitmap
. This is where the application crashes. Can someone tell me how do I fix this?