B4J Question From panel to panel and magnification

micro

Well-Known Member
Licensed User
Longtime User
Hi to all

Why the panel of origin suffers the same changes of the destination panel?

B4X:
Dim pimg As Pane
pimg = paneorigin
Dim jo As JavaObject = pimg
jo.runMethod("setScaleX", Array(4.0))
jo.runMethod("setScaleY", Array(4.0))

also paneorigin is enlarged 4 times
I want paneorigin not to change
Thanks
 

stevel05

Expert
Licensed User
Longtime User
Because assigning an object to another variable in that way just makes the new variable point to the original, it does not make a copy. You need to populate the second pane using the same method that you created the original i.e. loadlayout into the new pane.

Although if you are accessing the views within your code it would probably cause problems. A solution would be to create a duplicate layout with different variable names.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Another solution would be to wrap the pane in a class and deal with view interaction within the class.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Another solution would be to wrap the pane in a class and deal with view interaction within the class.
Ok, Thanks.
Another question, also if it is OT
How i can convert a image captured with snapshot in a monochrome image (0 for white and 1 for black) to have a better print result?
Is for printing labels.

Edit:
https://www.b4x.com/android/forum/threads/b4x-convert-bitmap-to-bmp-format.94420/
With this erel tips the result is better but i look for other better solutions, thanks.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I do very little with images, you would be better to create a new thread for this question, it will not be seen here by someone who may know.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Thanks to all for your suggestions.
for my work (create a small image (text and shapes) for a label print) this is more than satisfactory.

B4X:
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

Then i print as pdf with appropriate reduction (first I enlarge the pane 4 times)
 
Upvote 0
Top