简体   繁体   English

如何将GlideBitmapDrawable强制转换为BitmapDrawable

[英]How can cast GlideBitmapDrawable to BitmapDrawable reciprocaly

this code: 此代码:

imageView = (ImageView) findViewById(R.id.avatar);

Bitmap photo = ((GlideBitmapDrawable)imageView.getDrawable().getCurrent()).getBitmap();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG,100,bos);
byte[] bArray = bos.toByteArray();

return this error: 返回此错误:

E/AndroidRuntime: FATAL EXCEPTION: main E / AndroidRuntime:致命异常:main
java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable java.lang.ClassCastException:android.graphics.drawable.BitmapDrawable无法转换为com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable

Change this: 更改此:

Bitmap photo = ((GlideBitmapDrawable)imageView.getDrawable().getCurrent()).getBitmap();

To this: 对此:

Bitmap photo = ((BitmapDrawable)imageView.getDrawable().getCurrent()).getBitmap();

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM