0

First of all i searched a lot and didn't find solution for my case, i need to convert the imageUrl to drawable, what i tried as far :

File imageFile = DiskCacheUtils.findInCache(c.profilePhoto, com.nostra13.universalimageloader.core.ImageLoader.getInstance().getDiscCache());

            String file_target = "file://" + imageFile.getPath();


            BitmapDrawable bitDraw = (BitmapDrawable) BitmapDrawable.createFromPath(file_target);
            if (profilePhotos.size() == 4) break;
            BitmapDrawable drawable = bitDraw; //getResources().getDrawable(c.profilePhoto);
            drawable.setBounds(0, 0, width, height);
            profilePhotos.add(drawable);

Also i tried to load the image into bitmap via Glide, but didn't work.

How i can achieve that ?

Thanks in advance.

  • You tried these links? 1. https://stackoverflow.com/a/45073477/4116560 2. https://stackoverflow.com/a/45073604/4116560 – vss Aug 26 '17 at 12:37
  • `file_target` is not a path. `imageFile.getPath()` is a path. `createFromPath()`, based on its name, would appear to expect a path, and you are not providing a path. Beyond that, feel free to explain in actual computer programming terms what problems you have with your code snippet and what "but didn't work" means with respect to Glide. – CommonsWare Aug 26 '17 at 12:40
  • did you try `Drawable#createFromStream()`? – pskink Aug 26 '17 at 12:40
  • @sam your both url didn't provide a path for image. –  Aug 26 '17 at 12:47
  • @CommonsWare Good, I tried to get cached image via ImageLoader, in order to get path image that make me use it as drawable. but it's always failed with NPE exception or many other excpetions, how i can strt that and get the final result? ( a drawable image from url). –  Aug 26 '17 at 12:50
  • @pskink no i didn't try it, would you provide an example for that ? –  Aug 26 '17 at 12:51
  • The String named `urlPath` mentioned in the 1st link denotes the image path `Arduino Android`. If you want to download the image from that URLpath, you should create a path where you want to store. – vss Aug 26 '17 at 12:55
  • actually what do you need `Drawable` for? for showing on the `ImageView` or something else? – pskink Aug 26 '17 at 13:10
  • @pskink i need it to use as a multiple drawable, vijay solution worked but still facing some issue. –  Aug 26 '17 at 13:15
  • use `Drawable.createFromStream(inputStream, "someName")` - where `inputStream` is taken from `ContentResolver#openInputStream` method call – pskink Aug 26 '17 at 13:21

1 Answers1

1

first convert URL to Bitmap and pass bitmap into these function

Drawable d= new BitmapDrawable(context.getResources(), bitmap); return d;

Vijay Chaudhary
  • 228
  • 2
  • 12