Base64 encoding and decoding of Android pictures and method of decoding Base64 pictures

Base64 is one of the most common encoding methods for transmitting 8bit byte code on the network. Base64 is a method to represent binary data based on 64 printable characters.

Base64 encoding is a process from binary to character, which can be used to transfer long identification information in HTTP environment. For example, in the Java persistence system hibernate, Base64 is used to encode a long unique identifier (generally 128 bit UUID) into a string, which is used as a parameter in HTTP forms and HTTP get URLs. In other applications, it is often necessary to encode binary data into a form suitable for placement in URLs, including hidden form fields. At this time, Base64 coding is unreadable and can only be read after decoding.

1、 Code

Strbm is the encoded character.

2、 Decode

PS: Android decodes Base64 pictures

Recently, the HTML images in the project have been changed. Usually, the SRC of img tag returns the image path. Due to the change of background personnel, now the SRC of img tag returns a string of Base64 format codes. See the following figure for details:

Because when using WebView to display web pages, the function of previewing pictures was done, and loading pictures also directly took the picture link of Src in img tag to display pictures. After background changes, the pictures could not be previewed normally. This requires Base64 to decode strings. Specific code:

Note: the encoded picture will have "data: image / *; Base64, "ID, we need to remove this part during decoding, otherwise decoding will fail.

summary

The above is the base64 encoding and decoding of Android pictures and the method of decoding Base64 pictures introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>