java 如何将base64字符串转换为blob?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32732362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert base64 string to blob?
提问by gayan1991
A Synchronization service that provide an image in Base64
string and I want to save that into a SQLite
database blob
field?
提供Base64
字符串图像的同步服务,我想将其保存到SQLite
数据库blob
字段中?
Could anyone tell me how to proceed with this or any other way to do this procedure?
谁能告诉我如何进行此程序或以任何其他方式执行此程序?
As later on, I need to show image in bitmap.
稍后,我需要在位图中显示图像。
回答by Akshay Paliwal
You convert a base64 image string to byte[] like :
您将 base64 图像字符串转换为 byte[],例如:
byte[] decodedByte = Base64.decode(yourBase64String, 0);
after that you also can convert it to Bitmap :
之后,您还可以将其转换为 Bitmap :
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
回答by LebroNan
To convert a base64 string to a byte[], you can use:
要将 base64 字符串转换为 byte[],您可以使用:
byte[] decodedByte = Base64.decode(yourBase64String)
And to convert a byte[] to a blob, you can use:
要将 byte[] 转换为 blob,您可以使用:
Blob b = new SerialBlob(decodedByte);