Android Question How to Draw a bitmap on a page

Steven Buckley

Member
Licensed User
Longtime User
HI,
I have a C++ application that creates an image as an array of 24-bit RGB values. In the C++ design these colours are in a simple XY array (X=16 x Y=800). I want to simply write these colours as pixels on a page
in the Android App. Sorry if this is a bit elementary but I'm quite new to this. Can anyone give me a simple example of displaying such an array on a page? Many thanks in advance.
 

Cableguy

Expert
Licensed User
Longtime User
You can use a canvas for that!
 
Upvote 0

Steven Buckley

Member
Licensed User
Longtime User
Sorry if this is a bit elementary but I'm quite new to this. Can anyone give me a simple example of displaying such an array on a page? Many thanks in advance.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As Cableguy already suggested, you must use a Canvas.
Canvas has the DrawPoint(x, y, Color) method.
The code below draws a red square onto the Activity.
Up to you to extract the x, y and color calues from your data.

B4X:
Sub Globals
    Private cvsActivity As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    cvsActivity.Initialize(Activity)
    Draw
End Sub

Private Sub Draw
    Private x, y As Int
  
    For x = 100 To 500
        For y = 100 To 500
            cvsActivity.DrawPoint(x, y, Colors.Red)
        Next
    Next
End Sub
 
Upvote 0

Steven Buckley

Member
Licensed User
Longtime User
As Cableguy already suggested, you must use a Canvas.
Canvas has the DrawPoint(x, y, Color) method.
The code below draws a red square onto the Activity.
Up to you to extract the x, y and color calues from your data.

B4X:
Sub Globals
    Private cvsActivity As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    cvsActivity.Initialize(Activity)
    Draw
End Sub

Private Sub Draw
    Private x, y As Int
 
    For x = 100 To 500
        For y = 100 To 500
            cvsActivity.DrawPoint(x, y, Colors.Red)
        Next
    Next
End Sub
Perfect!
Many thanks for that.
 
Upvote 0

Steven Buckley

Member
Licensed User
Longtime User
That works fine. Unfortunately, I want to update the image fast. This seems to take a long time. The total image size is 800 x 1600 pixels.
I have no problem creating the 800x1600 pixel RGB COLORREF array. Is there a quicker way of updating the image?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Try one of the graphics advanced libs like accelerated surface by @Informatix
 
Upvote 0

Steven Buckley

Member
Licensed User
Longtime User
The data comes directly as a stream of bytes via Bluetooth (4 bytes per pixel as a RGB code). I'm interfacing with a
3D imaging system that usually streams the data via a high speed USB bus to a host PC. I am modifying the system,
for demo purposes, to work on an android smartphone. Whilst the frame rate wont be as good I have calculated that I
can still achieve about 3-4 frames a second, which is fine for demo purposes. That is, if I can get the data to the
the phone display as an image. Any help will be greatly appreciated.
 
Upvote 0
Top