Is there any simple way to rotate an imported image on a tkinter canvas? I'd rather not use the PIL module, but I can't find any viable alternatives. (If it helps, I want to rotate some car images when they take a turn on a crossroad.)
相关问题
- Django __str__ returned non-string (type NoneType)
- How to postpone/defer the evaluation of f-strings?
- ImportError shows up with py.test, but not when ru
- Comparing pd.Series and getting, what appears to b
- Tkinter Grid Columnspan ignored
相关文章
- tkinter这样怎么不能分别赋值?
- Airflow depends_on_past explanation
- Raspberry Pi-Python: Install Pandas on Python 3.5.
- Numpy array to TFrecord
- How to split a DataFrame in pandas in predefined p
- Why do people say “Don't use place()”?
- Where to learn tkinter for Python? [closed]
- Error following env.render() for OpenAI
Big thanks to @acw1668's answer on this page, which helped me to develop this more efficient solution.
It turns out the PhotoImage.put() method accepts string data and will write whatever pattern you give it as a string, on loop, to fill a given area within an image. So, instead of having to read each pixel one by one, and then write each pixel one by one, we can read each pixel and then write just once!
The function below allows you to rotate and mirror any PhotoImage object and does so in a fraction of the time that the pixel-for-pixel, read-write method does. Mirroring is accomplished by simply reading each row or column from back to front. Rotation writes each row as a column, which effectively turns the image 90 degrees.
And here's a simple example of usage:
Below is a simple but not efficient method to rotate a
PhotoImage
90 (right), 180 and 270 (left) degrees: