B4A Library Convert/Compress Image - WebP, JPG, PNG

Convert/Compress Image between different formats WebP, JPG, PNG.

ConvertImage

Author:
Pendrush
Version: 1.00
  • ConvertImage
    • Events:
      • OnComplete
      • OnError (Error As String)
    • Fields:
      • TO_JPEG As android.graphics.Bitmap.CompressFormat
        Compress to the JPEG format
      • TO_PNG As android.graphics.Bitmap.CompressFormat
        Compress to the PNG format. PNG is lossless, so quality is ignored
      • TO_WEBP As android.graphics.Bitmap.CompressFormat
        Compress to the WEBP format
    • Functions:
      • ConvertBitmapToFile (InputBitmap As android.graphics.Bitmap, SavePath As String, ToFormat As android.graphics.Bitmap.CompressFormat, Quality As Int)
        InputBitmap - Bitmap to compress
        SavePath - Path where new converted/compressed image will be saved
        ToFormat - Use one of constant TO_WEBP, TO_JPEG, TO_PNG
        Quality - From 0 to 100. Quality of 0 means compress for the smallest size. 100 means compress for max visual quality.
        Dim Bitmap1 As Bitmap = LoadBitmap(File.DirAssets, "test.png")
        Dim SavePathAndFileName As String = File.Combine(File.DirInternal, "test.webp")
        ConvertImage1.ConvertBitmapToFile(Bitmap1, SavePathAndFileName, ConvertImage1.TO_WEBP, 100)
      • Initialize (EventName As String)
        Initialize library
        ConvertImage1.Initialize("ConvertImage1")
 

Attachments

  • ConvertImageLibrary.zip
    2.5 KB · Views: 119
  • ConvertImageExample.zip
    31.3 KB · Views: 105
Last edited:

Magma

Well-Known Member
Licensed User
Excellent !

Hi there... is that only for b4a... if it is can port it to b4j too ?
 

asales

Well-Known Member
Licensed User
Thank you very much, @Pendrush .

This solved my problem to save an image in WEBP format.

Could you give more information about the code used to convert to the webp format?
This code could be used to create a cross platform like this BitmapToBMP?

Thanks again!
 

DonManfred

Expert
Licensed User
Top