B4A Library Palette - Create color palette from bitmap

For some (Material Design) color effects it is important to create a color palette or just a Highlight color from a Bitmap. Google added the Palette Class for this to the support library.
This is a wrapper for this class.

First some example images of the example app:


Installation:
You need to use B4A 6.30+ and the Android Support Repository must be installed with SDK Manager.
Copy all files (.xml, .jar, .aar) from the PaletteLibx_xx.zip file to your additional libraries folder.



Short usage sample:
B4X:
[...]
    Dim paletteBuilder As PaletteBuilder
    paletteBuilder.Initialize("Palette", ImageView1.Bitmap)
    paletteBuilder.GenerateAsync
[...]

Sub Palette_Generated (Palette As Palette)
    Panel1.Color = Palette.GetVibrantColor(Colors.Black)
    If Palette.VibrantSwatch <> Null Then
        Label1.TextColor = Palette.VibrantSwatch.BodyTextColor
        Label1.Text = "Vibrant: " & Palette.VibrantSwatch.Population
    Else
        Label1.TextColor = Colors.White
        Label1.Text = "Vibrant (not in Palette)"
    End If
[...]

First initialize a PaletteBuilder object with eventname and a bitmap which should be analyzed. Then call PaletteBuilder.GenerateAsync. You should not use PaletteBuilder.Generate in the UI thread since analyzing the image will take some time and the UI thread will be blocked!

If analyzing of the image is done, the "Generated" event will be fired with a Palette object as a parameter. The palette will have "vibrant" and "muted" colors that are extracted from the image. Additionally there are so called Swatches which have the normal color (.RGB property) and high contrast TitleText and BodyText colors.

See the example of the usage.

Official Android documentation

Reference:

Version History:
V1.0:
  • Initial version
 

Attachments

  • PaletteExample1_0.zip
    344.9 KB · Views: 484
  • PaletteLib1_0.zip
    7.3 KB · Views: 416
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…