B4J Question Can't load Webp into ImageView: webp._decode (java line: 45)

Ferdari

Active Member
Licensed User
Longtime User
When loading a webp file from assets or from every path, returns:
webp._decode (java line: 52)
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

Code:
B4X:
Dim wp As WebP
wp.Initialize

If wp.IsInitialized Then
    ImageView1.SetImage(wp.LoadWebP( File.ReadBytes(File.DirAssets,"e.webp")))
Else
    Log("WP not init")
End If
File has bytes and is readable, tried in Edge and Photos app and it works.

Tried JWebp and Webp Libraries, both returns error.

B4J Version 10.3

Error log:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
webp._loadwebp (java line: 52)
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at com.zakgof.webp4j.Webp4j.lambda$decode$1(Webp4j.java:44)
    at com.zakgof.webp4j.BITools.create(BITools.java:13)
    at com.zakgof.webp4j.Webp4j.decode(Webp4j.java:43)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at sticker.Parser.webp._loadwebp(webp.java:52)
    at sticker.Parser.main$ResumableSub_CrearPackdeStickers.resume(main.java:400)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:156)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1172)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:1589)
 
Last edited:

zed

Well-Known Member
Licensed User
I extracted this code from one of my applications.
B4J:
ImvThumb as B4XImageView

If File.Exists(UserCurrentFolder,media_title&".webp") Then
        Dim WebP1 As WebP
        WebP1.Initialize
        ImvThumb.Bitmap = WebP1.LoadWebP(File.ReadBytes(UserCurrentFolder, media_title&".webp"))
else
...
end if

Maybe just change ImageView1 to B4XImageView
 
Upvote 0

zed

Well-Known Member
Licensed User
Sorry, I didn't pay attention to the log.
The image may be empty or the file may no longer exist.

Test to see if the image is empty.
Test:
Dim bytes() As Byte = File.ReadBytes(File.DirAssets, "e.webp")

If bytes.Length > 0 Then
     ImageView1.SetImage(wp.LoadWebP(bytes))
Else
    Log("The e.webp file is empty or not found")
End If
 
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
Sorry, I didn't pay attention to the log.
The image may be empty or the file may no longer exist.

Test to see if the image is empty.
Test:
Dim bytes() As Byte = File.ReadBytes(File.DirAssets, "e.webp")

If bytes.Length > 0 Then
     ImageView1.SetImage(wp.LoadWebP(bytes))
Else
    Log("The e.webp file is empty or not found")
End If
i already tried, file is in Assets/Files and i can open it in other programs, also can log(bytes(indexes)) can check file size, and byte.length, but cant load into Webp library, its like webp lib can't read files or don't have access to files, i checked file Read permission/read-only
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Probably could be of help if you post some ptoblematic webp-Files.
Maybe they are incompatible/corrupt
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
In 2020 Erel wrote

You did like this post.



It is not a static image. It is an animated one. So i would not expect for it to work at all.
How can you expect/what let you think it should work?
Good observation, i expect only firstframe to render, like in android with same Lib, then with first frame resize to 96x96 to make a static PNG icon.

should try command-line cwebp then.

Thanks for your support @DonManfred 🙏
 
Upvote 0
Top