CameraX PreviewView.getBitmap() returns null


I want to scrop the camera image for Text Recognition.

I use previewView.getBitmap().

On the Android Studio Emulator it works fine.

But when i use it on my mobile it returns <null>.

Is there a fix?

As a workaround i try

BitmapUtils.getBitmap(ImageProxy);
-3
Oct 17 at 4:36 AM
User AvatarMaria Sumer
#android#google-mlkit

Accepted Answer

PreviewView.getBitmap() may return null if the preview has not produced a frame yet or the view is not fully initialized. Check that previewView is attached, has non-zero dimensions, and the camera preview is active before capturing.

For text recognition, using ImageAnalysis with an ImageProxy is generally more reliable than capturing a bitmap from the preview. Convert the frame to the format required by your OCR library, and close the ImageProxy after processing to avoid blocking subsequent frames.

User AvatarIndiancad
Oct 17 at 5:16 AM
0