My question is how to write image data held in a buffer to a bitmap for subsequent display in imageview or further manipulation?
With reference to the library I'm working on in this post, I am successfully capturing video frames sent via NDI with the data of each frame stored in a ByteBuffer:
So bytebuffer contains the data of each pixel in four bytes representing RGBA. I'm satisfied the data is being captured and stored in bytebuffer because I can read out the data for each pixel using:
to show:
Video data received (1920x1080, 50, PROGRESSIVE, RGBA)
0 | 122 | 72 | 125 | 27
1 | 122 | 72 | 125 | 27
2 | 122 | 72 | 125 | 27
3 | 123 | 72 | 125 | 27
4 | 123 | 73 | 125 | 28
5 | 122 | 73 | 125 | 27
6 | 122 | 73 | 125 | 27
7 | 122 | 73 | 125 | 26
8 | 122 | 73 | 127 | 26
9 | 122 | 73 | 127 | 26
10 | 122 | 73 | 126 | 26
11 | 122 | 74 | 126 | 26
12 | 122 | 72 | 126 | 27
13 | 122 | 72 | 126 | 27
14 | 122 | 72 | 126 | 27
15 | 122 | 72 | 126 | 27
16 | 121 | 72 | 125 | 27
17 | 121 | 72 | 125 | 27
18 | 121 | 72 | 125 | 27
19 | 121 | 72 | 125 | 27
20 | 121 | 71 | 125 | 28
21 | 121 | 71 | 125 | 28
22 | 121 | 71 | 125 | 28
23 | 121 | 71 | 125 | 28
24 | 120 | 71 | 124 | 28
Any guidance would be appreciated.
With reference to the library I'm working on in this post, I am successfully capturing video frames sent via NDI with the data of each frame stored in a ByteBuffer:
B4X:
Private bytebuffer As JavaObject
bytebuffer.InitializeStatic("java.nio.ByteBuffer")
bytebuffer = bytebuffer.RunMethod("allocateDirect",Array(videoFrame.XResolution * videoFrame.YResolution * 4))
So bytebuffer contains the data of each pixel in four bytes representing RGBA. I'm satisfied the data is being captured and stored in bytebuffer because I can read out the data for each pixel using:
B4X:
Log("Video data received (" & videoFrame.XResolution & "x" & videoFrame.YResolution & ", " & (videoFrame.FrameRateN / videoFrame.FrameRateD) & ", " & videoFrame.FormatType.toString & ", " & videoFrame.FourCCType.toString & ")")
For i = 0 To bytebuffer.RunMethod("capacity",Null) - 1 Step 4
Dim r, g, b, a As Byte
Log((i/4) & " | " & bytebuffer.RunMethod("get", Array(i)) & " | " & bytebuffer.RunMethod("get", Array(i+1)) & " | " & bytebuffer.RunMethod("get", Array(i+2)) & " | " & bytebuffer.RunMethod("get", Array(i+3)))
Next
to show:
Video data received (1920x1080, 50, PROGRESSIVE, RGBA)
0 | 122 | 72 | 125 | 27
1 | 122 | 72 | 125 | 27
2 | 122 | 72 | 125 | 27
3 | 123 | 72 | 125 | 27
4 | 123 | 73 | 125 | 28
5 | 122 | 73 | 125 | 27
6 | 122 | 73 | 125 | 27
7 | 122 | 73 | 125 | 26
8 | 122 | 73 | 127 | 26
9 | 122 | 73 | 127 | 26
10 | 122 | 73 | 126 | 26
11 | 122 | 74 | 126 | 26
12 | 122 | 72 | 126 | 27
13 | 122 | 72 | 126 | 27
14 | 122 | 72 | 126 | 27
15 | 122 | 72 | 126 | 27
16 | 121 | 72 | 125 | 27
17 | 121 | 72 | 125 | 27
18 | 121 | 72 | 125 | 27
19 | 121 | 72 | 125 | 27
20 | 121 | 71 | 125 | 28
21 | 121 | 71 | 125 | 28
22 | 121 | 71 | 125 | 28
23 | 121 | 71 | 125 | 28
24 | 120 | 71 | 124 | 28
Any guidance would be appreciated.