Jump to content
softtouch

Loading .webp images into tbitmap?

Recommended Posts

I need to convert some webp images to jpg or any other format (target format does not matter).

How can I load a .webp image into a timage without using any external dll/dylib like Skia4Delphi?

I just cant find anything realted to .webp and fmx.

Share this post


Link to post

I just realized, more or less by accident, that an FMX TBitmap can load WebP image files. I tested a few of them, but they seem to be all perfectly fine.

bmp := TBitmap.create;
bmp.LoadFromFile('C:\Users\Alexander\Pictures\_test.webp');

bmp.SaveToFile('C:\Users\Alexander\Pictures\_test.png'); //works
bmp.SaveToFile('C:\Users\Alexander\Pictures\_test.webp'); //this fails!

The load dialog in the IDE does not include webp, so you cannot select it. You can rename a webp image to ".bmp" and load it though. Internally, the TFixedMultiResBitmap converts it to PNG data, which heavily increases the binary image data stored in the form. It's like you had used a PNG in the first place. So, when using webP for UI display, it probably makes sense to store them as RC_DATA resources and load from a resource stream at runtime.

 

Saving WebP fails with an error.

 

The webp feature seems to come from the operating system. GDI+ explicitly mentions WEBP among other formats:

Image File Format Constants (Gdiplusimaging.h) - Win32 apps | Microsoft Learn

 

Does anyone know since when GDI+ supports WebP? 

Was this implemented in Windows 8 or Windows 10? I am pretty sure that Windows 7 GDI+ did not support it. Which means that an FMX app that runs on Win7 would not be able to load it at runtime.

 

fmx-tbitmap-webp.jpg

Share this post


Link to post
1 hour ago, Alexander Sviridenkov said:

Maybe this come from SKIA webp support?

Nope. Delphi 11.3 without Skia, just FMX with GDI+.

WebP works on MacOS as well, probably iOS, too.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×