简体   繁体   中英

Print an image on python 3.7

I am trying to print an image with Python (I use Thonny).

from PIL import Image, ImageDraw
import numpy as np

image_entrée = Image.open("Lenna.png")
image = np.asarray(image_entrée)
nb_lignes,nb_colonnes,_ = image.shape

image_sortie = np.copy(image)

Image.fromarray(image).save("image_entree.png")
Image.fromarray(image_sortie).save("image_sortie.png")

This code is coming from a website and I don't understand where I have to put my image. I tried to change the file name and the image name but nothing changes. It says that it can not find Lenna.png In which file do I have to put my.png image?

Thank you a lot for the time you will give me:)

program is looking for "Lenna.png" in the same directory where your python program is, one way is to copy Lenna.png or any other image you want to use to put in the same folder where your.py program is. the other way is give it as a path my_file_path=r"/Users/SimpleApp/Downloads/my_picture.png" and then use image_entrée = Image.open(my_file_path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM