Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用Python编写可以旋转图像的函数(cImage)_Python - Fatal编程技术网

如何用Python编写可以旋转图像的函数(cImage)

如何用Python编写可以旋转图像的函数(cImage),python,Python,如何编写代码?我只能想到这个: def rotateImage90CW(image): pic = FileImage(image) oldw = pic.getWidth() oldh = pic.getHeight() newIm = EmptyImage(oldw,oldh) for row in range (oldh): for col in range(oldw): oldPixel = pic.getPixel(col,row) newIm.

如何编写代码?我只能想到这个:

def rotateImage90CW(image):
pic = FileImage(image)
oldw = pic.getWidth()
oldh = pic.getHeight()
newIm = EmptyImage(oldw,oldh)
for row in range (oldh):
    for col in range(oldw):
        oldPixel = pic.getPixel(col,row)
        newIm.setPixel(oldw-row,col,oldPixel)
newIm.draw(myWin)
如果您使用PIL/枕头:

from PIL import Image
im = Image.open(image)
im.rotate(90).show()
在您的示例中,oldw row应为“row”