Hi, I want to get data in YCbCr_420_SP format from the Camera1_Preview event like this :
B4X:
Sub Camera1_Preview (PreviewPic() As Byte)
If DateTime.Now > lastPreviewSaved + IntervalMs Then
Dim in As InputStream
Dim bmp As Bitmap
in.InitializeFromBytesArray(PreviewPic, 0, PreviewPic.Length)
Log("Length PrevPicArr=" & PreviewPic.length)
Log(PreviewPic(2000)) ' is there something in the array ?
Try
bmp.Initialize2(in)
ImageView1.Bitmap = bmp
Panel2.setbackgroundimage(bmp)
Catch
Log("catch " & LastException)
End Try
lastPreviewSaved =DateTime.Now
End If
End Sub
the line bmp.Initialize2(in)" line gives this error in the catch .
java.lang.RuntimeException: Error loading bitmap. Sub
About your 2 last questions, the negative values aren't so in origin. But as the array holds 8-bit data and the only 8-bit basic type in android is (signed)byte, when you look at their value, they are signed. Better think of them as values ranging from 0x00 to 0xFF
A bitmap needs RGBA888 values when initialized in B4A. You could also used RGB565 with inline java or using existing libraries, but no NV21 YCbCr format
hi Jordi , i used your lib to changed the brightness ( Y luma) for a bitmap.
using the first 307200 bytes.
with this parameters :
camera is always in landscape
myBitmap.Width myBitmap.Height = 640 480
camEx.PreviewHeight camEx.PreviewWidth = 480 640
camEx rotation = 90
this works ok ! .
Are these resolutions preview resolutions or picture resolutions? (the camera gives you both)
Not sure to understand correctly your question:
> Do you mean that you want to work with the maximum preview resolution, only process a part of the preview data and then convert this part into a bitmap to show it on screen?
> If so, is it always the same "rectangle" and always the same operation or it can vary dinamically?
If what you want is that the bitmap fits the whole screen, just change in the example (in Activity_Create)
B4X:
'Activity.AddView(myIV,50%X,50%Y,50%X,50%Y) '<-- Comment this line
Activity.AddView(myIV,0,0,100%X,100%Y)'50%X,50%Y,50%X,50%Y) '<-- This line instead of the above
The bitmap will be the same but the system will scale it for you (you will see that if you choose scale=1, the quality is good enough. Also, if you must process the preview t is not a good idea to work with very high resolutions)