'Change brightness of markers in Flutter

I made PNGs for custom markers on my GoogleMap view. By using e.g.:

BitmapDescriptor bikeBlack = await BitmapDescriptor.fromAsset(const ImageConfiguration(), "assets/images/bike_black.png")

I obtain an object that I can use as a marker directly. However, I need to be able to change the brighness as well for about 50 markers of 4 different types, during runtime. The only possible solution I have come up with so far is creating 1024 different PNGs. This will increase app size by about 2MB but it might be a lot of work to do..

I cannot really afford using await statements since they slow the app down considerably. But if I have to, I can force myself to live with that.

As far as I can tell, a marker icon has to be a BitmapDescriptor. But I cannot find a way to change the brightness of such a BitmapDescriptor.

I'm close to just giving up and just writing a python script that will generate the 1,024 PNGs for me. But there must be a nicer and more efficient solution. If you have one, please let me know.

[EDIT]: I went with creating 1024 images. For anybody in the same situation, this is the script I used:

from PIL import Image, ImageEnhance

img = Image.open("../img.png")

enhancer = ImageEnhance.Brightness(img)

for i in range(256):
    img_output = enhancer.enhance(i / 255)
    img_output.save("img_{}.png".format(i), format="png")


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source