i use floodfill for fill white space between black area.
1- my problem is that floodfill algorithm cannot fill all space ,as you can see, some space in the edge. how Increasing the accuracy of the algorithm?
2- when i click on black lines, floodfill algorithm change the lines color, how can i prevent changing black lines color?
The problem is that the image being used was created with anti-aliasing. If you look at the forum example you will see exactly the same "missing pixels" as this poster is seeing. Flood fill will only fill pixels of the specified colour; shaded pixels around edges will not be the specified colour so will not be changed.
You could modify the pixel color comparison of this code so that instead of filling pixels that match a specified color, it instead fills pixels that do NOT match specified boundary color(s).
Or add a bit of stretchiness to the comparison, eg RGB components have to match within 32, rather than have to match precisely. Will only half-fix the issue, but better than nothing.
You could modify the pixel color comparison of this code so that instead of filling pixels that match a specified color, it instead fills pixels that do NOT match specified boundary color(s).
Or add a bit of stretchiness to the comparison, eg RGB components have to match within 32, rather than have to match precisely. Will only half-fix the issue, but better than nothing.
Private Sub ColorsEqual(pm1 As PremultipliedColor, pm2 As PremultipliedColor) As Boolean
Return pm1.r = pm2.r And pm1.g = pm2.g And pm1.b = pm2.b
End Sub
if so then try replacing that color comparison with something like this:
B4X:
Private Sub ColorsEqual(pm1 As PremultipliedColor, pm2 As PremultipliedColor) As Boolean
Dim MaxDifference As Int = 64 '0 = exact match
If Abs(pm1.r - pm2.r) > MaxDifference Then Return False
If Abs(pm1.g - pm2.g) > MaxDifference Then Return False
If Abs(pm1.b - pm2.b) > MaxDifference Then Return False
Return True
End Sub
Do you have control over the original images ie before recoloring?
If so, then what would solve the problem is to ensure that the image only contains the few b-color-area pixel colors, and save the image in a lossless format eg (preferably) PNG or (possibly might also work) GIF with no dithering.
if so then try replacing that color comparison with something like this:
B4X:
Private Sub ColorsEqual(pm1 As PremultipliedColor, pm2 As PremultipliedColor) As Boolean
Dim MaxDifference As Int = 64 '0 = exact match
If Abs(pm1.r - pm2.r) > MaxDifference Then Return False
If Abs(pm1.g - pm2.g) > MaxDifference Then Return False
If Abs(pm1.b - pm2.b) > MaxDifference Then Return False
Return True
End Sub
I am pretty sure that the only 100% fix is to modify the base image to remove dithering and interpolations and antialiasing, so that it only uses the few actual intended palette colors.
If you can post an original of an image before you:
then I will try various fixes here.
I am pretty sure that the only 100% fix is to modify the base image to remove dithering and interpolations and antialiasing, so that it only uses the few actual intended palette colors.