如何为Base64字符串转换成位图图像显示在一个ImageView的? [英] How to convert a Base64 string into a BitMap image to show it in a ImageView?
本文介绍了如何为Base64字符串转换成位图图像显示在一个ImageView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Base64的字符串,再presents位图图像。
我要改变这种字符串为位图图像再次使用它放在一个ImageView的在我的Android应用程序
怎么办呢?
这是我用来转换图像为Base64编码字符串的code:
// proceso日transformar德拉imagen画质的BitMap EN联合国字符串:
//android:src="c:\logo.png
资源R = this.getResources();
位图BM = BitmapFactory.de codeResource(R,R.drawable.logo);
ByteArrayOutputStream BAOS =新ByteArrayOutputStream();
bm.com preSS(Bitmap.Com pressFormat.PNG,100,BAOS); // BM是位图对象
byte []的B = baos.toByteArray();
//字符串连接codeDIMAGE = Base64.en code(B,Base64.DEFAULT);
EN codeDIMAGE = Base64.en codeBytes(B);
解决方案
您可以基本上只是使用一些其他内置的方法还原您的code。
字节[]德codedString = Base64.de code(EN codeDIMAGE,Base64.DEFAULT);
位图德codedByte = BitmapFactory.de codeByteArray(德codedString,0,德codedString.length);
I have a Base64 String that represents a BitMap image.
I need to transform that String into a BitMap image again to use it on a ImageView in my Android app
How to do it?
This is the code that I use to transform the image into the base64 String:
//proceso de transformar la imagen BitMap en un String:
//android:src="c:\logo.png"
Resources r = this.getResources();
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.logo);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
//String encodedImage = Base64.encode(b, Base64.DEFAULT);
encodedImage = Base64.encodeBytes(b);
解决方案
You can just basically revert your code using some other built in methods.
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
这篇关于如何为Base64字符串转换成位图图像显示在一个ImageView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文