Reputation: 1156
I am facing difficulties in implementing a custom camera view.
The task I want to achieve is - in camera preview I got a preview picture (in previewcallback function). I zoom it and then I want to draw the zoomed version of the image in the camera view.
In previewcallback function I got image pixel values as byte array. But in canvas.drawImage it accepts int array. Can anyone suggest me how does the pixel data is organized in the byte array within the previewcallback function?
I tried to lock the surfaceview but it didn't help. It returns null so I cannot draw anything on that surface.
Any suggestions? thanks.
Upvotes: 0
Views: 418
Reputation: 12367
As said previously, NV21 is default and has to be provided always - this means you can rely on it and you shal rely on it if you like to be compatible with other devices. As for locking surface view - surface view you are using for preview is off limits for you since it is already locked by camera applciation ( which is nativeand runs in own process ) - if you like to use it, you will have to stop preview on it so camera app releases this surface ( hopefully )
Bad news is that you can not place another surface view on top of the first with frame layout
( this is limitation of surface views, they can not overlap ), but good news is that you can place image view oevr it and draw your bitmap there ( via runOnuiThread()
)
You can find example how to do this in our javaOCR project
( see android demos, please use git repo as it is current )
Upvotes: 1
Reputation: 18107
The way the pixel data from the preview callback is organized depends on what your preview format is set to. By default, it is NV21, which is the most compatible option across Android devices. You can find more detail about this format here, for example.
But roughly, the image data is in a YCbCr format - not the more common RGB color encoding that canvas would want. You'll need to
Upvotes: 2