是否可以使用 PNG 图像的十六进制值设置 Android 图像?
所以我的代码看起来像这样:
ImageView imageView = new ImageView();
String test = intent.getStringExtra(AndroidPoS.MESSAGE_KEY2 + ".PNG"); //MESSAGE_KEY2 contains the hex value for the image
imageView.setImageResource(test);
我知道这不能编译,但这可以让您对我想要实现的目标有一个基本的了解。如果有人对如何实现这一点有任何想法,我们将不胜感激。
谢谢
最佳答案
我认为最好的解决方案是以某种方式将十六进制字符串转换为实际的字节数组。这很可能已经在某个地方得到了解决。一旦你有了这个字节数组,我们称之为imagebytes
,你就可以这样做:
Bitmap bmp = BitmapFactory.decodeByteArray(imagebytes, 0, imagebytes.length);
您可以在这里阅读有关 BitmapFactory 的信息:http://developer.android.com/reference/android/graphics/BitmapFactory.html
这里回答了类似的问题: How to convert byte array to Bitmap
关于java - 使用十六进制值设置 Android 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18577235/