Sub CaptureImageLabel
Dim v As B4XView = mylabel '(pane)
Dim jo As JavaObject = v
jo.runMethod("setScaleX", Array(4.0))
jo.runMethod("setScaleY", Array(4.0))
Dim bmp As B4XBitmap = v.Snapshot
Dim bc As BitmapCreator
Dim xui As XUI
bc.Initialize(bmp.Width, bmp.Height)
bc.CopyPixelsFromBitmap(bmp)
Dim a0, a1, a2 As ARGBColor
bc.ColorToARGB(xui.Color_White, a0)
bc.ColorToARGB(xui.Color_Black, a1)
For y = 0 To bc.mHeight - 1
For x = 0 To bc.mWidth - 1
bc.GetARGB(x, y, a2)
If a2.a > 0 Then
If a2.r > 200 And a2.g > 200 And a2.b > 200 Then
bc.SetARGB(x, y, a0)
Else
bc.SetARGB(x, y, a1)
End If
End If
Next
Next
'
Dim b() As Byte = BitmapToBMP(bc.Bitmap) '?
File.WriteBytes(File.DirApp, "label.bmp", b)'?
End Sub
'v This is a Erel code for a sub
Sub BitmapToBMP (img As B4XBitmap) As Byte()
Dim Padding As Int = 4 - ((img.Width * 3) Mod 4)
If Padding = 4 Then Padding = 0
Dim HeaderSize As Int = 40
Dim offset As Int = HeaderSize + 14
Dim size As Int = offset + img.Width * img.Height * 3 + img.Height * Padding
Dim raf As RandomAccessFile
Dim buffer(size) As Byte
raf.Initialize3(buffer, True)
raf.WriteBytes(Array As Byte(Asc("B"), Asc("M")), 0, 2, raf.CurrentPosition)
raf.WriteInt(size, raf.CurrentPosition)
raf.CurrentPosition = raf.CurrentPosition + 4
raf.WriteInt(offset, raf.CurrentPosition)
raf.WriteInt(HeaderSize, raf.CurrentPosition)
raf.WriteInt(img.Width, raf.CurrentPosition)
raf.WriteInt(img.Height, raf.CurrentPosition)
raf.WriteShort(1, raf.CurrentPosition)
raf.WriteShort(24, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
raf.WriteInt(0, raf.CurrentPosition)
Dim bc As BitmapCreator
bc.Initialize(img.Width, img.Height)
bc.CopyPixelsFromBitmap(img)
Dim a As ARGBColor
For y = bc.mHeight - 1 To 0 Step -1
For x = 0 To bc.mWidth - 1
bc.GetARGB(x, y, a)
raf.WriteByte(a.b, raf.CurrentPosition)
raf.WriteByte(a.g, raf.CurrentPosition)
raf.WriteByte(a.r, raf.CurrentPosition)
Next
For i = 0 To Padding - 1
raf.WriteByte(0, raf.CurrentPosition)
Next
Next
raf.Close
Return buffer
End Sub