How to rotate image 90 degrees(counterclockwise and clockwise ) in python Here i
ID: 3567745 • Letter: H
Question
How to rotate image 90 degrees(counterclockwise and clockwise ) in python
Here is my code r1 for clockwise, r2 for counterclockwise
def r1(img):
w = img.getWidth()
h = img.getHeight()
new = Picture(h,w)
for y in range(h):
for x in range(w):
r,g,b = img.getPixel(x,y)
new.setPixel(y,x,[r,g,b])
def r2(img):
w = img.getWidth()
h = img.getHeight()
new = Picture(h,w)
for y in range (h):
for x in range (w):
r,g,b = img.getPixel(w-x-1,h-y-1)
new.setPixel(y,x,[r,g,b])
New image is rotating, but not directly 90 degree, more like rotate 90 degree and flip it horizontally.
Can somebody to help me fix my python problem?
Explanation / Answer
But this is clearly not the most optimized way because you'll compute X images instead of the one you are interested in. I suggest you try a basic switch...case approach first (even if this statement doesn't exists in Python ;):
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.