How change specific color in image to transparent in Flutter

Viewed 110

I want to change black background of my image to transparent, I receive an image base64 encoded format. I can change color to other colors, but not working with alpha. This is my code Example.

List<int> switchColor(Uint8List bytes, ) {
final image = External.decodeImage(bytes);
final pixels = image!.getBytes(format: External.Format.rgba);
final int length = pixels.lengthInBytes;
for (var i = 0; i < length; i += 4) {
      if (pixels[ i + 1] == 0 &&pixels[ i ] == 0 &&pixels[ i + 2] == 0) {
    pixels[i + 3] = 0;
  }
 }
return External.encodePng(image);
}
0 Answers
Related