How to flood-fill part of a bitmap enclosed by a black border with my chosen color?

前端 未结 2 518
孤城傲影
孤城傲影 2020-12-06 08:22

I want to programmatically modify a bitmap using python but don\'t really need a thorough grounding in the subject, so would like to concentrate on learning just what I need

2条回答
  •  天涯浪人
    2020-12-06 09:07

    PIL has an undocumented function ImageDraw.floodfill:

    >>> import ImageDraw
    >>> help(ImageDraw.floodfill)
    Help on function floodfill in module ImageDraw:
    
    floodfill(image, xy, value, border=None)
        Fill bounded region.
    

    (Flood-filling should generally be a last resort because it interacts poorly with anti-aliased lines. It is usually better to get the actual boundary data for the counties and then draw a filled polygon. However, PIL doesn't support anti-aliased line drawing so this advice is useless unless you switch your drawing module to something more capable like PythonMagick or pycairo.)

提交回复
热议问题