iOS Question JPEG byte array to Bitmap for iOS

Andrew A Gray

Licensed User
I found this code for B4A. It displays a jpeg image in memory onto the screen.
It works!

    Dim jpeg() As Byte = camEx.PreviewImageToJpeg(Prev, 70)

    Log("Cam1_Preview ms: " & (l - lastPrev) & " Size : " & Prev.Length & " " & jpeg.Length)
    Dim ins As InputStream
    Dim bmp As Bitmap
    Dim imgtest As ImageView
    ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
    imgtest.Gravity = Gravity.FILL
    Activity.AddView(imgtest, 10dip, 10dip, 100dip, 100dip)
    imgtest.Bitmap = bmp

Now I need to do the same thing for iOS. (That's the whole point about B4X, correct?)

So everything moves over except:

1) Gravity.FILL is not defined for iOS.
2) Apparently, there is no "Activity" for iOS.
What is used to "AddView", then?

In other words, the BitMap bmp is created OK, so how do I display it
on the iOS screen?

Do I use a Panel?
And then use something like
Page1.RootPanel.AddView(View as Object, Left, Top, Width, Height)

If so, then imgtest (as ImageView) is the wrong type of "View" and does not work!!??

OK, now I see:
LoadBitmap works in b4a not in b4i

Here you create an ImageView with the designer. I will try this and get back.

Andrew Gray
Last edited:

Andrew A Gray

Licensed User
OK, I created an ImageView1 in designer.
I've got an output stream image "out" from Cam Preview from CCTV
I want to put the "out" back frozen to the 1280x720 iphone screen.

I created a Test Button to start it:

Sub TestButton_Click
   Log( "Test Button" )
   Dim ins As InputStream
   Dim bmp As Bitmap
   'Dim imgtest As ImageView
   'Put output stream bytes into input stream
   ins.InitializeFromBytesArray(out.ToBytesArray, 0, out.ToBytesArray.Length)

   'Put input stream bytes into bitmap
   ImageView1.Width = 1280   
   ImageView1.Height = 720
   'imgtest.Gravity = Gravity.FILL
   'Activity.AddView(imgtest, 0dip, 0dip, 640dip, 480dip)
   'Activity.AddView(imgtest, 0, 0, 640, 480)
    ImageView1.Bitmap = bmp
    LoadImageFromBitMap( ImageView1 , bmp, 0)

End Sub

Here is the function:

Private Sub LoadImageFromBitMap(im As ImageView,bm As Bitmap,Angle As Int)                                                                      
      Dim Rect1 As Rect
      Dim canvas1 As Canvas
      Rect1.Initialize(0, 0, 1280, 720 )
      canvas1.DrawBitmapRotated(bm, Rect1, Angle)  
End Sub

Shouldn't this work? What am I doing wrong?
Upvote 0