Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Why do you need to convert it to a string? Strings are for characters, not for images. Strings in Python are not arbitrary bunches of bytes and there are bound to be byte subsequences in your image data that are meaningless when treated as Unicode codepoints. So if you try to convert to a string you will probably get encoding errors. Bytestrings are there to let you do what you are doing without having to worry about what the bytes might mean when interpreted as characters. Commented Dec 27, 2020 at 16:20
  • How about converting to base64? en.m.wikipedia.org/wiki/Base64 Commented Dec 27, 2020 at 16:49
  • @wuerfelfreak I have tried with base64 but when I try it to encode back to image I am getting error. Commented Dec 27, 2020 at 18:52
  • @BoarGules I want to convert it to string because I wanna perform some ciphering operation on image. Commented Dec 27, 2020 at 18:53
  • You can encipher a bytestring. In fact, most encryption library functions expect bytestrings, because insisting on Python strings would prevent users like you from doing what you want to do. Commented Dec 27, 2020 at 19:10