brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.16k stars 262 forks source link

Mask flood does not work correctly #263

Open mlopezdetrinidad opened 3 years ago

mlopezdetrinidad commented 3 years ago

Hi,

I am trying to implement a bucket functionality on a coloring app that I am developing, but when I have used the mask flood functionality some corners of the image are not covered.

do you have any idea why is it happening?

I will appreciate your help.

Regards,

brendan-duncan commented 3 years ago

I don't know why, I didn't write the function so I'm not that familiar with it. Can you provide an example demonstrating the issue and I can take a look at it.

mlopezdetrinidad commented 3 years ago

Hi,

Sorry for my late answer, I am doing the following:

` final RenderRepaintBoundary boundary = _coloring.boundaryKey.currentContext.findRenderObject() as RenderRepaintBoundary; final ui.Image image = await boundary.toImage(); final ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png); final img.Image currentImage = img.decodeImage( byteData.buffer.asUint8List(), ); final interpolation = currentImage.width / widthScreen; final dx = (localPosition.dx.floor() interpolation).floor(); final dy = (localPosition.dy.floor() interpolation).floor();

var pixelColor = currentImage.getPixel(
  dx,
  dy,
);

if (pixelColor == 4278190080) {
  return;
}

Uint8List imageMask = img.maskFlood(
  currentImage,
  dx,
  dy,
  threshold: 100.99,
  compareAlpha: true,
  fillValue: 1,
);

Path pathBucket = potraceMask(
  imageMask,
  currentImage.width,
  currentImage.height,
  opttolerance: 0.0,
);`

But I am getting the following result:

image

if you see some angles of the image are not filling like in the tail of the unicorn.

But I don't what could be the issue.

Thank you.

Regards,

brendan-duncan commented 3 years ago

Can you give me the original image?

mlopezdetrinidad commented 3 years ago

I am loading SVG string on CANVAS and then getting the repaint boundary of the widget that contains the canvas, I don't know if the SVG string works for you?

brendan-duncan commented 3 years ago

Then just from looking at it, I would guess the anti-aliasing of the SVG rendering is keeping the flood-fill from getting into those corners. Maybe play with the tolerance values?

mlopezdetrinidad commented 3 years ago

I will play with the tolerance values, there could be the issue.

thanks a lot.