Reputation: 1653
Is it possible to set an android Image using the Hex value of a PNG image??
So my code looks something like this:
ImageView imageView = new ImageView();
String test = intent.getStringExtra(AndroidPoS.MESSAGE_KEY2 + ".PNG"); //MESSAGE_KEY2 contains the hex value for the image
imageView.setImageResource(test);
I know this doesnt compile but that gives you a basic idea of what I am trying to achieve. If anyone has any ideas on how to implement this it would be much appreciated.
Thanks,
Upvotes: 1
Views: 2234
Reputation: 32
I think the best solution would be to somehow convert the hex String to an actual byte array. It is highly probable that this was solved somewhere already. And as soon as you have that array of bytes, let's call it imagebytes
, you can do this:
Bitmap bmp = BitmapFactory.decodeByteArray(imagebytes, 0, imagebytes.length);
You can read about BitmapFactory here: http://developer.android.com/reference/android/graphics/BitmapFactory.html
A similar question was answered here: How to convert byte array to Bitmap
Upvotes: 1
Reputation: 10938
That doesn't really give an idea of what you are trying to do. What do you mean by the 'hex value of a png'? A single hex value would account for one pixel in the png
If you mean how do you convert the name of a drawable to its int resource id, for example if you have R.drawable.yourdrawable and you want to find out the int value using "yourdrawable", you can use something like
context.getResources().getIdentifier(name, resType, context.getPackageName());
Where name is the name of the file (without extension ex "yourdrawable") and resType is "drawable", "color", "integer" etc
However, you can pass R.drawable.yourdrawable as an Integer extra in the intent. Using the identifier is slower than using the id and is discurraged
Upvotes: 0