2015-09-23 64 views
1

提供Base64字符串中的图像的同步服务,我想将其保存到SQLite数据库blob字段中?如何将base64字符串转换为blob?

任何人都可以告诉我如何继续这个或任何其他方式来做这个过程?

后来,我需要在位图中显示图像。

+0

base64转换为位图,则位映射为byte [],此字节[]到Db.make确保您的列名有型有斑点 – Sree

+0

有在http一个战利品://wiki.lenux .org/base64-string-to-blob-object/ –

回答

5

:你将一个base64图像串为byte [],如:

byte[] decodedByte = Base64.decode(yourBase64String, 0); 

你也可以将其转换为位图:

Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); 
+0

我想我们应该更新: 'byte [] decodedByte = Base64.decoder.decode(yourBase64String,0); ' – Tung

+0

“yourBase64String”是怎么样的?是否有可能“137,80,78,71,13,10,26,10,0,0 ...” – mehmet

0

要cnovert的base64字符串字节[],您可以使用:

byte[] decodedByte = Base64.decode(yourBase64String) 

并将一个字节[]转换为blob。你可以使用:

Blob b = new SerialBlob(decodedByte); 
相关问题