2

How can load images from an url with ion ? Image should be a bitmap.

Example: Bitmap image=Ion.with(this).load('url')

How can I achive this ?

Library:https://github.com/koush/ion

2 Answers 2

9

You should probably do it asynchronously. Here is an example:

Ion.with(this).load("url").withBitmap().asBitmap()
        .setCallback(new FutureCallback<Bitmap>() {
            @Override
            public void onCompleted(Exception e, Bitmap result) {
                // do something with your bitmap
            }
        });
4
  • Thank you so much it worked.I have one more question.Do you know how can I clear ion image cache when user closes the app Nov 1, 2014 at 0:33
  • Either Ion.getDefault(this).getCache().clear(); or Ion.getDefault(this).getBitmapCache().clear(); You can do this in activity's onPause()/onDestroy() method.
    – EyesClear
    Nov 1, 2014 at 0:35
  • Thank you so much,you saved my day bro :) Nov 1, 2014 at 0:37
  • I got this error: "The type com.koushikdutta.async.future.Future cannot be resolved. It is indirectly referenced from required .class files" Anyone got it too? Dec 20, 2014 at 15:29
4

It can also be loaded synchronously if needed. For example:

Bitmap image = Ion.with(this)
    .load("url")
    .withBitmap()
    .asBitmap()
    .get();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.