koush / ion

Android Asynchronous Networking and Image Loading
Other
6.29k stars 1.03k forks source link

Modify image after loading #550

Open GoltsevEugene opened 9 years ago

GoltsevEugene commented 9 years ago

Goog afternoon. I'm using this beautiful library, but faced next issue: after image was loaded, I need to modify it (set it rounded, for example) and after that show it in ImageView. Unfortunately, I didn't find a way to handle it.

Here is the code:

Ion.with(img.getContext())
                  .load(link)
                  .intoImageView(img)
                  .setCallback(new FutureCallback<ImageView>() {
                      @Override
                      public void onCompleted(Exception e, final ImageView imageView) {
                          if (e != null) return;

                          imageView.buildDrawingCache();
                          Bitmap bmap = imageView.getDrawingCache();
                          final Bitmap bm = getRoundedCornerBitmap(bmap, imageView.getWidth() / 2);
                          imageView.setImageBitmap(bm);
                          activity.runOnUiThread(new Runnable() {
                              @Override
                              public void run() {
                                  imageView.invalidate();
                              }
                          });
                      }

                  });

If I remove operations with image - it is loading fine, otherwise - image is empty. Would be very grateful if there is some possibility to do this.

nschwermann commented 9 years ago

Referencing this bug may help you if you want to write your own drawable. https://github.com/koush/ion/issues/552

If you just want a rounded image check this out https://github.com/koush/ion/blob/master/ion-sample/src/com/koushikdutta/ion/sample/RoundedImageViewSample.java