Android将base64编码转化成图片
程序员文章站
2022-03-30 22:02:05
...
类似base64流的图片解析并展示:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcH Bw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAPUAooDAREAAhEBAxEB/8QAHQAAAQUBAQEBAAAAAAAAAAAAAgABAwQFBgcICf/EAE0QAAEDAgQEAwUGBAUCBAQEBwEAAgMEEQUSITEGQVFhEyJxBxQygZEjQqGxwfAVUtHhJDNDYnII8RZTgpIlNETCF2Oy0iZUc4OTouL/xAAaAQEBAQEBAQEAAAAAAAAAAAAAAQIDBAUG/8QAMxEBAQACAgICAgIBAwMEAgIDAAECEQMhEjEEQRNRIjJhBRRxQoGRIzNSsQahFtEVQ+H/2gAMAwEAAhEDEQA/APSwPovG+kKyaDgKhwinsgIBRRs3Cs9oEg3XSMlZVD2QKyGj2QPZArIFZEIhA1rJoJNKSaQrJoMRzVQ1lNKVk0FZUNZQK11QxCIrSDzlVAEISGITsMQnYaybU1imwkCtooHsgYhSQMQgVkCRSVQ1t0DW0QK3ZA1kNlYKhH1SBBpJ0CJY0W55cvlsALLWMKevj8RjWnQjZay7SM59O9vK/oudioiLaWU0prIgbIGIQMRqmgxCnYYpIBsm1MQUE1INJP8AiVqJVQhQLkiBKKYogCiBKKY9VAxQoCiGKACgYoBKAToEKEoBOpVoAogHKVYByJQOCbIBQ09NAXN6D2QPZFOApsPZNqIBEGweZWAea6sEgcIFZArIHQKyBWKBW0V2hWU2piFU0Vk2pWQLom00YoGsh2QQJArIGQVn/EqyAhUNZRTdkQkU1kCsVE0ayKQ0QKyBWTYVlIGtoqGI+aBEJAypsipo2VlUpiLa8kW09Nknfljka4jcApqm40oKUNFyFuYokkkigb5it9RGfNUulkuBYDZc7n2ujtl6pvadnc2N+4CuoIn0oOrHfVTxXaCSF7NwVnVhURHVZ2gVVMUDFQDzRTFEWaSN9nafENFqFVJo3RvLXizgpQCiAOiqhKBiFNpoJQCUAlECVFMVUCUDFAJQCUAlABCATsgjJQ9AKIBymwCNaen2XN22cBA4sgSNCCFOAoDYNVqIGy6MHsgeyBIEgcboG5oHQKyBKhEIGsmkJNKShsrKkMQiGtqi7KyBWRAkIqvIPMqyCybOjWTaUJCKVkoSWmi9E0aKylCsgVkDWQN+KBdkCAQNZA1lTRFDY4IzI42F7C5CsmwDrPOVo3NiCr4/Q4vFoazCONaKehe4QzOAkJWjIySBigRQMgSBggSBuSBFChOyJs1yro2/9k=
将Base64数据流转换为可展示的Bitmap(kotlin语言)
val decode: ByteArray = Base64.decode(qrCodeUrl.split(",").get(1), Base64.DEFAULT)
bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.size)
注意:含有“data:image/*;base64”的头的编码,在decode的时候就要去掉,否则是无法还原成功的。
去掉头部,kotlin语言
qrCodeUrl.split(",").get(1)
再将bitmap转化成图片!
在线图片转换成Base64数据流网站
https://tu.sioe.cn/gj/tupian-shujuliu/
推荐阅读