Android Question [Solved] Fails to convert a transparent PNG to WebP

asales

Well-Known Member
Licensed User
Longtime User
I'm trying to create a webp image from a PNG file (generated by a panel capture) using the ConvertImage lib made by @Pendrush .

It works fine if I use a solid background, but the convert fails If I use an transparent backuground.

I don't see any errors in the default logs, but I get this lines in the unfiltered logs:
B4X:
true
Fatal signal 11 (SIGSEGV), code 1, fault addr 0x90900000 in tid 17146 (example.savepng)
debuggerd: handling request: pid=17146 uid=11131 gid=11131 tid=17146
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'motorola/athene_t/athene_t:7.0/NPJS25.93-14-18/3:user/release-keys'
Revision: 'p2ad'
ABI: 'arm'
pid: 17146, tid: 17146, name: example.savepng  >>> b4a.example.savepng <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x90900000
    r0 908ff003  r1 00000800  r2 00000200  r3 908ff803
    r4 9079fe00  r5 00000200  r6 9079fff0  r7 908fffe3
    r8 00000ffc  r9 908ff803  sl 00000200  fp 00000001
    ip 00000200  sp be85f318  lr 9079fc00  pc ae9d9f24  cpsr 600d0010
backtrace:
    #00 pc 002e4f24  /system/lib/libskia.so
    #01 pc 00300cd0  /system/lib/libskia.so
    #02 pc 003004fc  /system/lib/libskia.so
    #03 pc 003005e4  /system/lib/libskia.so (WebPPictureImportRGBA+36)
    #04 pc 0029c047  /system/lib/libskia.so (_ZN18SkWEBPImageEncoder8onEncodeEP9SkWStreamRK8SkBitmapi+302)
    #05 pc 0009cb5b  /system/lib/libandroid_runtime.so
    #06 pc 018ccfe3  /system/framework/arm/boot-framework.oat (offset 0x15f4000) (android.graphics.Bitmap.nativeCompress+158)
    #07 pc 018ce44b  /system/framework/arm/boot-framework.oat (offset 0x15f4000) (android.graphics.Bitmap.compress+230)
    #08 pc 000a91c1  /system/lib/libart.so (art_quick_invoke_stub_internal+64)
    #09 pc 004031e9  /system/lib/libart.so (art_quick_invoke_stub+232)

(...)
This is the code and my example is in attached.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
   
    ConvertImage1.Initialize("ConvertImage1")
   
    lst.Initialize
    TextRnd
End Sub

Sub Button1_Click  
    Dim str As String = lst.Get(Rnd(0, lst.Size-1))
    label1.Text = str.ToUpperCase
   
    SaveImagePNG(Starter.SharedFolder, "1.png")
End Sub

Private Sub Button2_Click
    Log(File.Exists(Starter.SharedFolder, "1.png"))
    Dim Bitmap1 As Bitmap = LoadBitmap(Starter.SharedFolder, "1.png")
    Dim SavePathAndFileName As String = File.Combine(Starter.SharedFolder, "1.webp")
   
    ConvertImage1.ConvertBitmapToFile(Bitmap1, SavePathAndFileName, ConvertImage1.TO_WEBP, 70)
    ImageView2.Bitmap = LoadBitmap(Starter.SharedFolder, "1.webp")
End Sub

Sub SaveImagePNG(img_dir As String, img_nome As String)
    Dim x As B4XView = pnlCapture1
    Dim b As Bitmap = x.Snapshot

    Dim out As OutputStream
    out = File.OpenOutput(img_dir, img_nome, False)
    b.Resize(512, 512, True).WriteToStream(out, 100, "PNG")
    out.Close
   
    ImageView1.Bitmap = LoadBitmap(img_dir, img_nome)
End Sub

Sub TextRnd
    lst.Add("Lorem ipsum 1")
    lst.Add("LOREM IPSUM 2")
    lst.Add("DOLOR SIT AMET 3")
    lst.Add("LOREM 4")
    lst.Add("IPSUM 5")
    lst.Add("DOLOR SIT 6")
    lst.Add("SIT AMET 7")
End Sub

Thanks in advance for any tip to solved this problem.
 

Attachments

  • SavePNG.zip
    94.9 KB · Views: 99

Pendrush

Well-Known Member
Licensed User
Longtime User
It's a low level crash. I just tested and work as expected on my side.
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
TextRnd
** Activity (main) Resume **
LOREM IPSUM 1
SaveImagePNG: 1.png
true

1623097811655.png

Can try your code on some other device or emulator?
 

Attachments

  • images.zip
    36.3 KB · Views: 96
Last edited:
Upvote 0

asales

Well-Known Member
Licensed User
Longtime User
Thanks @Pendrush .
It seems the problem is in the device.
I tested in a Moto G4 with Android 7 and have the problem.
Tested again in a new device (Samsung A71 with Android 11) and works fine.
 
Upvote 0
Top