简体   繁体   English

IonDrawable无法转换为android.graphics.drawable.BitmapDrawable

[英]IonDrawable cannot be cast to android.graphics.drawable.BitmapDrawable

Trying to insert and image to Rounded Image using RoundedDrawable Class (Got it from https://github.com/vinc3m1/RoundedImageView ). 尝试使用RoundedDrawable类(从https://github.com/vinc3m1/RoundedImageView获得它)将图像插入并映射到“ Rounded Image”。

The image is from a URL. 该图像来自URL。 If I use Koushik dutta's ION library for the image loading part I get the following error: 如果我将Koushik dutta的ION库用于图像加载部分,则会出现以下错误:

 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? 看起来ION库支持ImageView不支持自定义的Image View? Has anybody got issue like this if so how was it solved? 是否有人遇到过这样的问题,如何解决?

Thanks! 谢谢!

I personaly use Ion's callback to set the ImageView 's Bitmap myself, and make it circular (or whatever) then: 我个人使用Ion的回调ImageView自行设置ImageViewBitmap ,然后使其变为圆形(或其他形式),然后:

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. 这种常规结构使您可以以任何所需的方式使用Bitmap

EDIT: If you are using Support Library v4, you should use RoundedBitmapDrawable instead: 编辑:如果您正在使用支持库v 4 ,则应改用RoundedBitmapDrawable

final RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
roundedBitmapDrawable.setCornerRadius(Math.min(roundedBitmapDrawable.getMinimumWidth(), roundedBitmapDrawable.getMinimumHeight()) / 2.0F);
imageView.setImageDrawable(roundedBitmapDrawable);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NinePatchDrawable无法转换为android.graphics.drawable.BitmapDrawable - NinePatchDrawable cannot be cast to android.graphics.drawable.BitmapDrawable android.graphics.drawable.AdaptiveIconDrawable 无法转换为 android.graphics.drawable.BitmapDrawable 错误 - android.graphics.drawable.AdaptiveIconDrawable cannot be cast to android.graphics.drawable.BitmapDrawable error java.lang.ClassCastException:android.graphics.drawable.ColorDrawable无法转换为android.graphics.drawable.BitmapDrawable - java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable java.lang.ClassCastException:android.graphics.drawable.BitmapDrawable无法转换为android.graphics.drawable.LayerDrawable - java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.LayerDrawable android.graphics.drawable.BitmapDrawable 不能转换为 java.lang.CharSequence - android.graphics.drawable.BitmapDrawable cannot be cast to java.lang.CharSequence NotSerializableException:android.graphics.drawable.BitmapDrawable - NotSerializableException: android.graphics.drawable.BitmapDrawable 如何在Android中使用android.graphics.drawable.bitmapdrawable? - How to use android.graphics.drawable.bitmapdrawable in android? 在目标类android.graphics.drawable.BitmapDrawable上找不到类型为int的getAlpha()方法 - Method getAlpha() with type int not found on target class class android.graphics.drawable.BitmapDrawable 无法转换为android.graphics.drawable.ColorDrawable - Cannot be cast to android.graphics.drawable.ColorDrawable Android:无法将BitmapDrawable强制转换为ClipDrawable - Android: cannot cast BitmapDrawable to a ClipDrawable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM