开发者

Python `aggdraw` module bug (?): visible alpha channel

Imagine simple script:

from PIL import Image
from aggdraw import Draw, Brush

im = Image.new("RGBA", (600, 600), (0, 0, 0, 0))
draw = Draw(im)

brush = Brush("yellow")

draw.polygon(
             (
              50, 50,
              550, 60,
              550, 550,
              60, 550,
             ),
             None, brush
            )

draw.flush()
开发者_JAVA百科im.save("2.png")

And the result:

Python `aggdraw` module bug (?): visible alpha channel

(Sorry for big size but that is more clearly)

And the problem: Can you see non-yellow and non-white edges? This is the alpha-channel or something.

When I trying to do this only with PIL's Draw object - it looks clearly and good but not anti-aliased.

But with aggdraw's Draw object it looks anti-aliased but with that ugly dirty edges.

I need exactly polygons with non-standard side angles. Simple box is not what I want.

Please, help me with some good optimistic answer how to solve this problem.


It's because your background is black, but transparent. If you set your image background to white, you don't get the visible edges. Either transparent or solid white works in my simple tests.

Try these values:

transBlack = (0, 0, 0, 0)         # shows your example with visible edges
solidBlack = (0, 0, 0, 255)       # shows shape on a black background
transWhite = (255, 255, 255, 0)
solidWhite = (255, 255, 255, 255)

im = Image.new("RGBA", (600, 600), solidWhite)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜