字符串为位图的Java / Android的位图、字符串、Android、Java

2023-09-04 06:34:21 作者:愛很美情很深

我正在开发中,我转换为位图,以字符串一些purprose的应用程序。 我如何可以转换字符串成位图了吗?

解决方案   

我转换成一个位图转换为字符串做一些工作,现在我想将其转换回......它看起来像android.graphics.Bitmap@43fd34c0

简单地说,你不能。

这串由默认 Object.toString()法生产。它没有连接code中的对象的信息内容,并没有什么标准的类库,这将打开它变成一个引用原始对象......假设它仍然存在。

您唯一的希望是,如果你创建一个地图<字符串,位图> 和映射填充;例如,

 地图<字符串,位图>图=新的HashMap<字符串,位图>();
...
map.put(someBitmap.toString(),someBitmap);
...
位图检索= map.get(someString);
 
Android开发学习路线之Java基础学习

I am developing an application in which I converted a bitmap to string for some purprose. How can I convert that String into a Bitmap again?

解决方案

I converted an Bitmap to String to do some work, now I want to convert it back... it looks like "android.graphics.Bitmap@43fd34c0"

Simply stated, you can't.

That string is produced by the default Object.toString() method. It does not encode the information content of the object, and there is nothing in the standard class libraries that will turn it back into a reference to the original object ... assuming that it still exists.

Your only hope is if you create a Map<String,Bitmap> and populate it with mappings; e.g.

Map<String, Bitmap> map = new HashMap<String, Bitmap>();
...
map.put(someBitmap.toString(), someBitmap);
...
Bitmap retrieved = map.get(someString);