我遇到了一个问题,通过选择图库图片并将其保存为Base64
String
保存在一个XML文件中(以备后用,例如,如果退出应用程序并再次打开它)。如何从InputStream获取Base64字符串?
正如你可以看到我坐上InputStream
的形象,但首先是onClick
方法:
public void onClick(DialogInterface dialog, int which) {
pictureActionIntent = new Intent(Intent.ACTION_GET_CONTENT);
pictureActionIntent.setType("image/*");
startActivityForResult(pictureActionIntent,GALLERY_PICTURE);
}
在
onActivityResult
方法我想从
InputStream
将图像存储到
Base64
String
现在。
case GALLERY_PICTURE:
if (resultCode == RESULT_OK && null != data) {
InputStream inputstream = null;
try {
inputstream = getApplicationContext().getContentResolver().openInputStream(data.getData());
Base64InputStream in = new Base64InputStream(inputstream,0);
} catch (IOException e) {
e.printStackTrace();
}
@EDIT 这是我创建的base64字符串后做。
Bitmap bmp = base64EncodeDecode.decodeBase64(Items.get("image"));
Image1.setImageBitmap(bmp);
这是解码方法:
public Bitmap decodeBase64(String input) {
byte[] decodedByte = Base64.decode(input, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
}
我试图用Base64InputStream
但没有成功。 你能给我一个提示如何从InputStream
到Base64
String
?
它将采取多少步骤并不重要。
我希望有人能帮助我!
亲切的问候!
太棒了!感谢你的代码!你能告诉我什么'format.format(新日期...'是? – raymondis
ohhh。用于将当前日期格式化为'dd_MM_yyyy_hh_mm_ss_aa'这种格式。我将编辑答案。 – ELITE
哦,是的,没关系。谢谢! – raymondis