Importing Image

0 votes

Hello guys, when I import an image it shows: 

UnicodeDecodeError: "utf-8" codec can"t decode byte 0xa0 in position 10: invalid start byte
code:
def importImage():
    result[0] = filedialog.askopenfile(mode = 'r', title = "Select file", initialdir =      "/home/amine/Bureau/desktop", filetypes = (("jpg files", ".jpg"), ("all files", ".*")))
    openImage = Image.open(result[0])
    resiszeImage = openImage.resize((247, 248))
    myImage = PhotoImage(resiszeImage)
    uploadCnavs.config(image = myImage)
Jun 25, 2020 in Python by Amine
• 120 points

edited Jun 25, 2020 by MD 131 views

1 answer to this question.

0 votes

Hi@Amine,

The error is because there is some non-ASCII character and it can't be encoded/decoded.  One simple way to avoid this error is to encode such strings. You can use the below line in your code. 

openImage = Image.open(result[0],encoding="utf8")
answered Jun 25, 2020 by MD
• 95,300 points

Related Questions In Python

+1 vote
2 answers

How to resize the image canvas to maintain a square aspect ratio

down voteacceptedUsing OpenCVYou can use resize() in OpenCV to ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,780 points
578 views
0 votes
1 answer

How to resize image canvas to maintain square aspect ratio in Python, OpenCv

Building on Alexander-Reynolds answer above, here is ...READ MORE

answered Sep 4, 2018 in Python by Priyaj
• 58,140 points
3,651 views
0 votes
1 answer

How to save Numpy array as image in python?

If you have matplotlib, you can do: import ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,520 points
7,491 views
0 votes
1 answer

Need help checking the validity of an image file in Python

I went through the Python documentation and ...READ MORE

answered Jan 18, 2019 in Python by Nymeria
• 3,520 points
993 views
0 votes
1 answer

Convert HTML to an image in Python

webkit2png. The original version is OSX-only, but luckily ...READ MORE

answered Feb 5, 2019 in Python by SDeb
• 13,300 points
12,485 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,421 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,818 views
+1 vote
1 answer

tensorflow is installed but theres an error while importing

Hi@Christlan, This problem is related to version. Follow ...READ MORE

answered Dec 22, 2020 in Python by MD
• 95,300 points
1,336 views