![](/img/trans.png)
[英]Barcode Google Vision API check if detected barcode is inside area
[英]Android Image to Bitmap for use in Google Vision Barcode api
我需要將android.media.Image
轉換為BitMap
以便可以在Google Vision Barcode API中使用它。 我嘗試了以下方法...
byte[] imageData = new byte[image.getPlanes()[0].getBuffer().remaining()];
Bitmap bmp = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
Frame frame = new Frame.Builder().setBitmap(bmp).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
System.out.println(barcodes.valueAt(0));
...但是出現以下錯誤:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference.
Google的示例代碼引用了不贊成使用的Camera
API,但我使用的是camera2
,這就是為什么我不能使用它們來獲取幫助的原因。
解決方法是確保imageReader
為JPEG
格式而不是YUV
mImageReader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 3);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.