我需要在图片左侧的半径为20的角45(月亮)中创建一个半圆。我不熟悉Python中的图像处理。我已经下载了PIL库,任何人都可以给我一个建议? 感谢用Python在角度45中创建一个半圆
0
A
回答
1
这可能会做你想要什么:
import Image, ImageDraw
im = Image.open("Two_Dalmatians.jpg")
draw = ImageDraw.Draw(im)
# Locate the "moon" in the upper-left region of the image
xy=[x/4 for x in im.size+im.size]
# Bounding-box is 40x40, so radius of interior circle is 20
xy=[xy[0]-20, xy[1]-20, xy[2]+20, xy[3]+20]
# Fill a chord that starts at 45 degrees and ends at 225 degrees.
draw.chord(xy, 45, 45+180, outline="white", fill="white")
del draw
# save to a different file
with open("Two_Dalmatians_Plus_Moon.png", "wb") as fp:
im.save(fp, "PNG")
编号:http://effbot.org/imagingbook/imagedraw.htm
这个程序可能满足新描述要求:
import Image, ImageDraw
def InitializeMoonData():
''''
Return a 40x40 half-circle, tilted 45 degrees, as raw data
Only call once, at program initialization
'''
im = Image.new("1", (40,40))
draw = ImageDraw.Draw(im)
# Draw a 40-diameter half-circle, tilted 45 degrees
draw.chord((0,0,40,40),
45,
45+180,
outline="white",
fill="white")
del draw
# Fetch the image data:
moon = list(im.getdata())
# Pack it into a 2d matrix
moon = [moon[i:i+40] for i in range(0, 1600, 40)]
return moon
# Store a copy of the moon data somewhere useful
moon = InitializeMoonData()
def ApplyMoonStamp(matrix, x, y):
'''
Put a moon in the matrix image at location x,y
Call whenever you need a moon
'''
# UNTESTED
for i,row in enumerate(moon):
for j,pixel in enumerate(row):
if pixel != 0:
# If moon pixel is not black,
# set image pixel to white
matrix[x+i][y+j] = 255
# In your code:
# m = Matrix(1024,768)
# m = # some kind of math to create the image #
# ApplyMoonStamp(m, 128,128) # Adds the moon to your image
相关问题
- 1. OpenGL - 创建一个圆,改变半径?
- 2. 如何在三个js中创建一个半圆柱体?
- 3. 在Cocoa中创建半透明,圆角的边框窗口?
- 4. CSS - 倒圆角半径画一个圆角
- 5. 在java脚本和CSS中构建半圆进度条带圆角和阴影
- 6. 创建一个圆圈用梯度
- 7. 在场景套件中创建半圆
- 8. 如何在Android中创建一个半圆ProgressBar
- 9. SKSpriteNode - 创建一个圆角节点?
- 10. 创建一个圆角视图
- 11. 如何创建一个圆角的NSImageView?
- 12. 试图创建一个圆角UIButton类
- 13. 创建一个带圆角的按钮
- 14. 创建一个圆角的BlockArrow
- 15. 圆角半径使用JavaScript
- 16. 45度角度切分格
- 17. 在Python中创建一个圆用两个鼠标点击
- 18. 在一个div创建一个半透明的响应三角
- 19. 在WPF/C中绘制一个半圆/半圆#
- 20. 如何在MFC中使用圆角创建进度控件?
- 21. 用CSS圆角创建一条线
- 22. 创建圆角在IE7/IE8
- 23. 用Chipmunk物理创建一个圆,但半径太大?
- 24. 用textview创建圆的半边框
- 25. 从另一个角度创建一个角度
- 26. 如何使用jQuery创建半圆进度条
- 27. 使用CAGradientLayer一个角/圆弧梯度
- 28. 如何在Flex中创建一个虚线圆角矩形?
- 29. 创建45度角投影的变换数学是什么?
- 30. 如何创建圆角半透明蒙版
不知道这帮助,但这个问题有几个答案... http://stackoverflow.com/questions/2980366/ draw-circle-pil-python – tjoenz
Python不是绘图工具。根本不是。试试inkscape。 –
什么是“45角的半圆”?你可以张贴一张照片吗? – Kevin