Closed ember11498 closed 1 month ago
same problem here. plz~~
maybe you can use ClipRRect?
you should handle the image data base on the crop rect, and setPixel to transparent out of the circular
final imageBytes = await _image!.readAsBytes();
img.Image originalImage = img.decodeImage(imageBytes)!;
int size = originalImage.width > originalImage.height ? originalImage.height : originalImage.width;
img.Image circularImage = img.Image(size, size);
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
int centerX = size ~/ 2;
int centerY = size ~/ 2;
int radius = size ~/ 2;
if (((x - centerX) * (x - centerX) + (y - centerY) * (y - centerY)) <= radius * radius) {
int srcX = (x * originalImage.width / size).toInt();
int srcY = (y * originalImage.height / size).toInt();
circularImage.setPixel(x, y, originalImage.getPixel(srcX, srcY));
} else {
circularImage.setPixel(x, y, img.getColor(0, 0, 0, 0));
}
}
}
I have asked this before but I got a vague response. After reading the example I still could not crop the image correctly as a circle. Can anyone point what how to have a circle editor crop layer that actually crops a circle?