iOS Question Who can help me to create b4i library?


Well-Known Member
Licensed User
As far as I can remember I have used something from github to convert webp to png. I have to search that. I will move those codes to a class and will post tonight or tomorrow.
Upvote 0


Active Member
Licensed User
Longtime User
You cannot use "jar" libraries in iOS.

I try to wrap an object c method named pngwithwebp,but when i use it in b4i, Warning show:Types do not match,and debug error:
Error occurred on line: 164 (Main)
-[UIImage imageWithWebp::]: unrecognized selector sent to instance 0x282618700
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  CoreFoundation       <redacted> + 1408
  CoreFoundation       _CF_forwarding_prep_0 + 92
  B4i Example          -[b4i_main _button2_click] + 788
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  B4i Example          +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
  B4i Example          -[B4IShell runMethod:] + 448
 B4i Example          -[B4IShell raiseEventImpl:method:args::] + 1648
 B4i Example          -[B4IShellBI raiseEvent:event:params:] + 1580
 B4i Example          __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
 libdispatch.dylib    <redacted> + 24
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1068
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1924
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 104
 UIKitCore            UIApplicationMain + 212
 B4i Example          main + 124
 libdyld.dylib        <redacted> + 4

My b4i code:
Dim w2p As webp2png
Dim ss As Bitmap  ss=w2p.imageWithWebp(File.Combine(File.DirTemp,"1.webp"))
'IV is ImageView

Hi Erel,can you give me some advices? thank you.


    51.4 KB · Views: 284
Last edited:
Upvote 0


Active Member
Licensed User
Longtime User
Something is wrong with your library. The method name includes two colons and there is only one parameter.

It will probably be simpler to use NativeObject to access the native library.
Thank you,it depend on 3rd part framework, can't use NativeObject. I upload the project file, I don't know where the problem is.
you can download the 3rd part framework from,it is WebpFramework-1.0.0.
Upvote 0


Active Member
Licensed User
Longtime User
That's wrong. You can add a reference to the framework with #AdditionalLib.

Thank you,Erel, Using NativeObject is a bit difficult for me,for the AdditionalLib is only the part of the object-c library(Written by others),I have no ability to modify too much.
The good news is that my first wrapping is successful via modifying only a few object-c library code.Webp image is successfully decoded and displayed in IOS imageview.
My goal is to decode the webp image and display in the wkwebview.My idea is to save the image on imageview to File.DirDocuments or other directory first,then show on wkwebview via LoadUrl method. I find these code from b4a,but not working and no error in b4i:
Dim bmpImage As Bitmap
Dim Canvas1 As B4XCanvas
Dim out As OutputStream
Dim IV as ImageView
Dim WKWeb as wkwebview
If bmpImage.IsInitialized Then
    out = File.OpenOutput(File.DirDocuments, "1.jpg", False)
end if
I use File.Exists method to see if 1.jpg exists and the result does not exist and wkweb don't load 1.jpg. I don't know where the problem is.
Last edited:
Upvote 0


Well-Known Member
Licensed User
Copy WebP.framework to your local build server's Libs folder
Add this to your project #AdditionalLib: WebP.framework
Paste this objc code at the bottom
#if objc
#import <WebP/decode.h>

-(UIImage *)convertWebPToUIimage: (NSString *) filePath{
    NSData *myData = [NSData dataWithContentsOfFile:filePath];
    int width = 0;
    int height = 0;
    WebPGetInfo([myData bytes], [myData length], &width, &height);
    uint8_t *data = WebPDecodeRGBA([myData bytes], [myData length], &width, &height);
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data, width*height*4, free_image_data);
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
    CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4*width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
    return [UIImage imageWithCGImage:imageRef];

static void free_image_data(void *info, const void *data, size_t size)
    if(info != NULL)
    {WebPFreeDecBuffer(&(((WebPDecoderConfig *)info)->output));}
    {free((void *)data);}

#End If

Then use it like below
Dim no As NativeObject = Me
Dim bmp As Bitmap = no.RunMethod("convertWebPToUIimage:",Array(File.Combine(File.DirAssets,"1.webp")))

Dim Out As OutputStream
Out = File.OpenOutput(File.DirDocuments, "image.png", False)
bmp.WriteToStream(Out, 100, "PNG")
Last edited:
Upvote 0


Active Member
Licensed User
Longtime User
Hi Brandsum ,many thanks, You gave me the method that Erel said.I test it and works. Now we have two ways to use webp image in IOS.Of course, using
RunMethod is simpler.
Upvote 0