【问题标题】:How can cast GlideBitmapDrawable to BitmapDrawable reciprocaly如何将 GlideBitmapDrawable 相互转换为 BitmapDrawable
【发布时间】:2018-01-30 15:30:12
【问题描述】:

这段代码:

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: 致命异常: main
java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable 不能转换为 com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable

【问题讨论】:

  • 你试过这篇文章了吗-->stackoverflow.com/questions/37701061/…
  • 实际上我使用 Bitmap.createScaledBitmap(bmp,x,y,bool) 将图像加载到 ImageView 中,现在我想使用 Glide (GlideBitmapDrawable) 检索它以存储在数据库中
  • 这部分是我想要的,也是相反的

标签: java android android-glide


【解决方案1】:

改变这个:

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

到这里:

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

【讨论】:

  • 你试过你的代码了吗?如果没有,为什么对任何反对票感到惊讶?
  • 我只是根据有问题的错误给出答案
  • GlideBitmapDrawableBitmapDrawable 无关,因此无法进行转换
猜你喜欢
  • 2015-02-02
  • 1970-01-01
  • 2015-06-17
  • 2015-11-16
  • 2020-10-29
  • 1970-01-01
  • 1970-01-01
  • 2015-07-15
  • 1970-01-01
相关资源
最近更新 更多