[Python Intermediate] Base64 encoding converts image data into strings

[Python Intermediate] Base64 encoding converts image data into strings

1. Background

When programming in Qt, some places such as the logo need to load pictures. After the program is packaged, the pictures need to be copied into the project.

Is it possible to convert the image into a string and use the string instead of the image address.
That is, in this way, it can be written into the py script in the form of a string variable.

Actually it can! This blog uses python3 to base64 encode the image, and a string data will be obtained after encoding, as shown in the figure below:
insert image description here

Introduction and application of base64:
Base64 is a representation method based on 64 printable characters to represent binary data.
Base64 is often used to represent, transmit, and store some binary data in situations where text data is usually processed, including MIME emails and some complex data in XML.
The BASE64 encoding of a picture is to encode a piece of picture data into a string of strings, and use the string instead of the picture address, so that there is no need to use the URL address of the picture.
Image to BASE64 encoding tool provides conversion of PNG to Base64, GIF to Base64, JPEG to BASE64 and other image format conversions. You only need to drag the image to the designated area to complete the operation!

The Base64 format is as follows:

 

Guess you like

Origin blog.csdn.net/jn10010537/article/details/131894686