I try to calculate the average color from SVG format Image, but I don't know how can an SVG Image from the network convert to Unit8List, ImageProvider, or BitMap!
for any of these types that I say, I can calculate the average color with the below code :
(I use image package)
import 'package:image/image.dart' as imgPack;
//
Unit8List _myHunit8List = ...
imgPack.Image bitmap = imgPack.decodeImage(_myHunit8List );
int redBucket = 0;
int greenBucket = 0;
int blueBucket = 0;
int pixelCount = 0;
for (int y = 0; y < bitmap.height; y++) {
for (int x = 0; x < bitmap.width; x++) {
int c = bitmap.getPixel(x, y);
pixelCount++;
redBucket += img.getRed(c);
greenBucket += img.getGreen(c);
blueBucket += img.getBlue(c);
}
}
Color averageColor = Color.fromRGBO(redBucket ~/ pixelCount,
greenBucket ~/ pixelCount, blueBucket ~/ pixelCount, 1);
how can I an SVG Image from the network
( I use flutter_svg package like:
SvgPicture.network(url);
) convert to Unit8List ?