2017-08-22 16 views
-1

验证码:如何可以投GlideBitmapDrawable到reciprocaly BitmapDrawable

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(); 

这个错误:

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable

感谢您的帮助:)

+0

做你试试这个职位 - > https://stackoverflow.com/questions/37701061/android-graphics-drawable-transitiondrawable-cannot-be-cast-to-com- bumptech-glid – slymnozdmrc

+0

实际上我用Bitmap.createScaledBitmap(bmp,x,y,bool)将图像加载到ImageView中,现在我想用Glide(GlideBitmapDrawable)检索它以存储在数据库中 –

+0

这部分是我想要的并且往回 –

回答

1

改变这一点: -

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

这个

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

你试过你的代码吗?如果没有,为什么惊讶的任何downvotes? – pskink

+0

我只是给出基于错误的问题,显示问题 –

+1

[GlideBitmapDrawable](http://bumptech.github.io/glide/javadocs/360/com/bumptech/glide/load/resource/bitmap/GlideBitmapDrawable.html)与'BitmapDrawable'无关,因此无法进行强制转换 – pskink