Android Question How to read images from Panel1 control to array ar in b4a, where ar is of Byte type?

bskotu555

Active Member
1745845099423.png
 

bskotu555

Active Member
Please post code as text. Not screenshot.

Tip: you should never call StartService(Starter).
b4a:
Dim bmp As Bitmap
        Dim outStream As OutputStream
        StartService(Starter)
        Dim tx As String=EditText1.Text
        bmp.InitializeMutable(Panel1.Width, Panel1.Height)
        'Panel1.DrawToBitmap(bmp)
        outStream.InitializeToBytesArray(0)
        bmp.WriteToStream(outStream, 100, "PNG")
        Dim ar() As Byte = outStream.ToBytesArray
 
Upvote 0

bskotu555

Active Member
Make sure that Panel1 is declared as B4XView and use Panel1.Snapshot to get a B4XBitmap with its content.
b4a:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Label1 As Label
    Private EditText1 As EditText
    Private smm As SimpleMediaManager
    Private chooser As MediaChooser
    Private Panel1 As B4XView
End Sub
Private Sub Button1_Click'拍照
    Wait For (chooser.CaptureImage) Complete (Result As MediaChooserResult)
    ShowMedia(Result)
End Sub

Private Sub ShowMedia (Result As MediaChooserResult)
    If Result.Success Then
        smm.SetMediaFromFile(Panel1, Result.MediaDir, Result.MediaFile, Result.Mime, Null)
    Else
        Panel1.RemoveAllViews
    End If
End Sub
 
Upvote 0

bskotu555

Active Member
Make sure that Panel1 is declared as B4XView and use Panel1.Snapshot to get a B4XBitmap with its content.
b4a:
outStream.InitializeToBytesArray(0)
        Panel1.Snapshot.WriteToStream(outStream, 100, "PNG")
        Dim ar() As Byte = outStream.ToBytesArray
        just like this?
 
Upvote 0

bskotu555

Active Member
B4A:
outStream.InitializeToBytesArray(0)
        Panel1.Snapshot.WriteToStream(outStream, 50, "PNG")
        Dim ar() As Byte = outStream.ToBytesArray
succeed
 
Upvote 0
Top