Search code examples
androiddynamicresourcespng

Create a PNG Resource dynamically


I'm trying in Android to get resources from an XML file sent from my server. It sends me a PNG file directly in Base64 format.

Like This :

lgrbehzlgrbezgbrhezugizgbrzbgre

My question is :

Is there a method to use the PNG data sent from my server as a resource like in "R.drawable.MyNewResource" ?

Or can I set ImageResoure from a PNG file in my application data folder ?

Thanks in advance!


Solution

  • Ok, your question is not proper, If I am not wrong then you want something like,

    Just convert your web response base64 png string into bitmap and then use that bitmap to set in imageview.

    Bitmap bitmap;          
    ImageView imgView;
    byte[] decodedString;       
    
    decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
    bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
    imgView.setImageBitmap(bitmap);