How to load a image from assets? How to load a image from assets? android android

How to load a image from assets?


You can follow my tutorials on displaying data from Assets: https://xjaphx.wordpress.com/2011/10/02/store-and-use-files-in-assets/
The sample with loading image and text to display.

I now added the relevant part of the provided link (in case of earthquake or something) ;-) Taifun

// load imagetry {    // get input stream    InputStream ims = getAssets().open("avatar.jpg");    // load image as Drawable    Drawable d = Drawable.createFromStream(ims, null);    // set image to ImageView    mImage.setImageDrawable(d);}catch(IOException ex) {    return;}


Instead of using the assets dir, put the file into /res/raw, and you can then access it using the following URI: android.resource://com.your.packagename/" + R.raw.radiocd5


try {    InputStream istr = this.context.getAssets().open(P.strImage);    //set drawable from stream    this.imgProduct.setImageDrawable(Drawable.createFromStream(istr, null));} catch (IOException e) {    e.printStackTrace();}