-1

How can I show some drawable programmatically created using ImageLoader.displayImage()?

According to documentation:

String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)

This only works using resource drawables

EDIT: I want to do something like:

Drawable drawable = ...
myImageView.setImageDrawable(drawable); // Using ImageLoader
user222
  • 191
  • 2
  • 17

2 Answers2

0
if(url != null && url != "")
  loader.displayImage(URLProtocol.parseURL(url, false), image)
else
  image.setImageResource(R.drawable.yourdrawable)

If you want to display a local drawable instead of a URL image with ImageLoad plugin, you can simply check if your URL exists and, if not, you can simply set the drawable as the image fir the ImageView.

Alessio Crestani
  • 1,602
  • 4
  • 17
  • 38
0

The best solution would be if you create a Bitmap from that Drawable and then save it to a File.

Use this to get the Bitmap from Drawable:

Drawable yourDrawable;  
Bitmap bitmap = ((BitmapDrawable)yourDrawable).getBitmap();

Create a File from Bitmap:

//create a file to write bitmap data
File f = File(context.getCacheDir(), filename);
f.createNewFile();

//Convert bitmap to byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();

//write the bytes in file
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();

Dont forget manifest permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

After you do this you can use Universal Image Loader to load the file to your ImageView

Ultimo_m
  • 4,724
  • 4
  • 38
  • 60