1

Trying to insert and image to Rounded Image using RoundedDrawable Class (Got it from https://github.com/vinc3m1/RoundedImageView).

The image is from a URL. If I use Koushik dutta's ION library for the image loading part I get the following error:

 09-27 21:35:06.187: E/AndroidRuntime(12606): FATAL EXCEPTION: main
 09-27 21:35:06.187: E/AndroidRuntime(12606): Process: com.ylg.maps, PID: 12606
 09-27 21:35:06.187: E/AndroidRuntime(12606): java.lang.ClassCastException: com.koushikdutta.ion.IonDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.ylg.otherlibs.RoudImageViewForMap.loadBitmap(RoudImageViewForMap.java:70)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.ylg.otherslibs.RoudImageViewForMap.onDraw(RoudImageViewForMap.java:80)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.view.View.draw(View.java:14465)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.view.View.draw(View.java:14350)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.view.ViewGroup.drawChild(ViewGroup.java:3103)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2940)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.view.View.buildDrawingCache(View.java:13673)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.view.View.buildDrawingCache(View.java:13522)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.ylg.maps.Mapsthree.createDrawableFromView(Mapsthree.java:454)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.ylg.maps.Mapsthree.loadFriends(Mapsthree.java:417)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.ylg.maps.Mapsthree.access$24(Mapsthree.java:402)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.ylg.maps.Mapsthree$LoadUsers.onPostExecute(Mapsthree.java:660)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.ylg.maps.Mapsthree$LoadUsers.onPostExecute(Mapsthree.java:1)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.os.AsyncTask.finish(AsyncTask.java:632)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.os.AsyncTask.access$600(AsyncTask.java:177)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.os.Handler.dispatchMessage(Handler.java:102)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.os.Looper.loop(Looper.java:136)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at android.app.ActivityThread.main(ActivityThread.java:5001)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at java.lang.reflect.Method.invoke(Native Method)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
 09-27 21:35:06.187: E/AndroidRuntime(12606):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

Looks like ION library support ImageView doesn't support customized Image View? Has anybody got issue like this if so how was it solved?

Thanks!

Community
  • 1
  • 1
TheDevMan
  • 5,914
  • 12
  • 74
  • 144
  • I encountered the same error and so i had to move to Picasso in order to solve it! – Pavlos Sep 28 '14 at 02:17
  • In Picasso... There is problem for me. I am actually converting the XML to bitmap and when I do that Picasso is not loading the image properly the first time. I sometimes get image or sometimes I get the placeholder image. Hence wanted to try a different library... – TheDevMan Sep 28 '14 at 02:41
  • Try Glide try UniversalImageLoader! There are plenty of libraries for such a job – Pavlos Sep 28 '14 at 02:49
  • @Pavlos: I have tried UniversalImageLoader too, but couldn't succeed. I am little confused with options that are available in UniversalImageLoader. How do I set the image... Here is what I am trying to use Picasso http://txs.io/lUrb. I believe ImageLoader doesn't activate Cache by default. Can you suggest a code for the above lines. Thanks! – TheDevMan Sep 28 '14 at 03:01

1 Answers1

6

I personaly use Ion's callback to set the ImageView's Bitmap myself, and make it circular (or whatever) then:

final ImageView imageView = (ImageView) ...
Ion.with(context)
    .load(url)
    .asBitmap()
    .setCallback(new FutureCallback<Bitmap>() {
            @Override
            public void onCompleted(final Exception e, final Bitmap bitmap) {
                // check for (e != null)
                final Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
                final BitmapShader shader = new BitmapShader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
                final Paint paint = new Paint();
                paint.setShader(shader);
                final Canvas canvas = new Canvas(circleBitmap);
                canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
                // maybe bitmap.recycle() here?
                imageView.setImageBitmap(circularBitmap);
            }
    });

This general structure allows you to work with Bitmap in any way you want.

EDIT: If you are using Support Library v4, you should use RoundedBitmapDrawable instead:

final RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
roundedBitmapDrawable.setCornerRadius(Math.min(roundedBitmapDrawable.getMinimumWidth(), roundedBitmapDrawable.getMinimumHeight()) / 2.0F);
imageView.setImageDrawable(roundedBitmapDrawable);
shkschneider
  • 17,833
  • 13
  • 59
  • 112