OPEN IMAGE USE OF PYTHON, showing an error

I try to open the image with python; I wrote the following code:

from PIL import Image im=Image.open("IMG_1930.jpg") im.show() 

But the Windows Photo Viewer opens, but instead of the photos, the following message is displayed:

"Windows viewer windows can not open this picture because a picture is deleted, or it is not in an accessible place."

0
source share
2 answers

Method show in PIL - it's a bad way to view the image - it is an application for viewing the hard coded image and records your image data to a temporary file before calling it as an external application.

What happens is that you either have problems with uneven access policies for Windows, and the viewer cannot open the file in the Python temporary directory, or there is a problem with the specifications of the Window path - it may even be a PIL error, which makes the temporary paht generated by the PIL an unusable image viewer.

If you use the show in the application window, use your way of viewing images captured to display it instead - otherwise, if it is more than a simple application, create Tkitner window and place the image in it for show .

 import sys import Tkinter from PIL import Image, ImageTk window = Tkinter.Tk() img = Image.open("bla.png") img.load() photoimg = ImageTk.PhotoImage(img) container = Tkinter.Label(window, image=photoimg) container.pack() Tkinter.mainloop() photoimg) import sys import Tkinter from PIL import Image, ImageTk window = Tkinter.Tk() img = Image.open("bla.png") img.load() photoimg = ImageTk.PhotoImage(img) container = Tkinter.Label(window, image=photoimg) container.pack() Tkinter.mainloop() 

(Linux users: some distributions require a separate installation Tkinter support for PIL / PILLOW For example, in Fedora, install the package. python-pillow-tk )

+2
source

I also had problems with this. Take a look at this post, he corrected my problem: PIL image show For () does not work in Windows 7

Good luck, correcting it.

0
source

All Articles