I’m trying to retrieve the color name from a hex code. I’m using a method where I capture image from a camera and extract the hex code from those images successfully. However, I’m struggling to accurately determine the corresponding color name.
I use this code get color name and hexcode:
`Future _getImageAndPickColor() async {
final pickedFile =
await ImagePicker().pickImage(source: ImageSource.camera);
if (mounted) {
Navigator.pop(context);
}
if (pickedFile != null) {
final bytes = await pickedFile.readAsBytes();
final image = img.decodeImage(Uint8List.fromList(bytes));
final pixelColor = image!.getPixel(image.width ~/ 2, image.height ~/ 2);
final red = pixelColor.r;
final green = pixelColor.g;
final blue = pixelColor.b;
_pickedColor =
Color.fromRGBO(red.toInt(), green.toInt(), blue.toInt(), 1);
_hexCode = _pickedColor.value.toRadixString(16).padLeft(8, '0').substring(2);
colorName(_hexCode);
_searching.text = _colorName;
print('colorName $_colorName');
print('hexcode $_hexCode');
searchFilter(_hexCode);
//showMyDialogForCamera(context);
}
}
`
New contributor
muhammad ahsan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.