Android Question PNG transparency lost after updating to B4A 13.40 (signature captured from Panel/Canvas)

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello everyone,

I have an app that captures a user's signature from a Panel used as a canvas and saves it to a PNG file:

Save Signature code:
Sub Save(SD As SignatureData, Dir As String, Name As String)
    Dim out As OutputStream
    out = File.OpenOutput(Dir, Name, False)
    SD.Canvas.Bitmap.WriteToStream(out, 100, "PNG")
    out.Close
End Sub

I then print that image with the EscPOSPRINTER class together with other content in a 40‑column report.

On B4A 12.80 everything works as expected. After updating to 13.40, it looks like the image transparency is lost: the printout shows solid/filled rectangles instead of the signature over a transparent background.

This seems to be related to how the image is saved. If I capture and save the signature using an APK compiled with 12.80, then update the app to the exact same code compiled with 13.40, the printout remains correct (no dark rectangles, transparency preserved). If I capture and save the signature with the 13.40 build, I get the dark smudges.

Any ideas ?
 

Attachments

  • I_250916_171656_31461.jpeg
    I_250916_171656_31461.jpeg
    377.1 KB · Views: 55

Pedro Caldeira

Active Member
Licensed User
Longtime User
Can you upload the saved PNG?
Here you have 4 png, 2 saved with v12.80 and 2 saved with v.13.40
Opening them via GIMP, they show the ones created via v13.40 as transparente png, instead of the ones created via v12.80, but strangely they appear black both in android and sometimes windows explorer, they sure appear black while trying to print them.
The first ticket printed correctly both in v12.80 and 13.40 as long as the image was saved in 12.80 the second is saved directly in 13.40.

Thanks in advance
 

Attachments

  • signature_1_1280.png
    signature_1_1280.png
    37.1 KB · Views: 19
  • signature_1_1340.png
    signature_1_1340.png
    27 KB · Views: 16
  • signature_2_1280.png
    signature_2_1280.png
    51.7 KB · Views: 12
  • signature_2_1340.png
    signature_2_1340.png
    25.1 KB · Views: 13
  • ticket_signatures_1340.jpg
    ticket_signatures_1340.jpg
    138.7 KB · Views: 19
  • ticket_signatures_1280.jpg
    ticket_signatures_1280.jpg
    110.5 KB · Views: 15
  • images_in_device.png
    images_in_device.png
    132.9 KB · Views: 17
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've made this test:
- Drawn a green circle with B4XCanvas.
- Used cvs.CreateBitmap to show the image with an ImageView.
- Saved the bitmap with WriteToStream and loaded it into another ImageView.

All three retained transparency:

1758777545009.png


B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim cvs As B4XCanvas
    cvs.Initialize(Panel1)
    cvs.DrawCircle(50dip, 50dip, 50dip, xui.Color_Green, True, 2dip)
    cvs.Invalidate
    ImageView1.SetBitmap(cvs.CreateBitmap)
    ImageView1.As(ImageView).Gravity = Gravity.FILL
    Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, "1.png", False)
    cvs.CreateBitmap.WriteToStream(out, 100, "PNG")
    out.Close
    ImageView2.SetBitmap(xui.LoadBitmap(xui.DefaultFolder, "1.png"))
    ImageView2.As(ImageView).Gravity = Gravity.FILL
End Sub

And project is attached.
 

Attachments

  • 1.zip
    15.7 KB · Views: 0
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello Erel,
Yes, What I noticed from checking the png files, is that the previous version saved the png with a white background, while this one saves it indeed transparent as it should.
The printer does not recognizes the transparency and prints it black.
I have solved it by setting the background of the canvas white, prior to drawing the signatures.
Thanks for your reply and analysis.
This post serves at most, to whoever uses the ESCPOSPRINTER functionalities, that they cannot use directly transparent png's or they get a black smudge.
 
Upvote 0
Top