Android 位图到 Base64 字符串 [英] Android Bitmap to Base64 String

查看:30
本文介绍了Android 位图到 Base64 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将大型位图(用手机相机拍摄的照片)转换为 Base64 字符串?

How do I convert a large Bitmap (photo taken with the phone's camera) to a Base64 String?

推荐答案

使用以下方法将位图转换为字节数组:

use following method to convert bitmap to byte array:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();

使用以下方法从字节数组编码base64

to encode base64 from byte array use following method

String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);

这篇关于Android 位图到 Base64 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆