将colorDrawable转换为位图

时间:2018-05-14 08:28:11

标签: android bitmap google-signin colordrawable

我正在尝试保存来自Google登录的个人资料图片,并且在这方面有点像菜鸟,所以我是以一种相当圆润的方式来做这件事。可能有更好的方法来做到这一点,如果您知道,请告诉我。但我认为我的问题有一个未解决的问题。所以 - 我们走了。

String profilePicUrl = googleSignInAccount.getPhotoUrl().toString();

ImageView intermediaryIV = (ImageView) 
findViewById(R.id.intermediary);
Glide.with(this).load(profilePicUrl).into(intermediaryIV);

ColorDrawable drawable = (ColorDrawable) intermediaryIV.getDrawable();
Bitmap toSaveBitmap = drawable.get; //??

savePicToInternalStorage(toSaveBitmap)

Glide api(https://github.com/bumptech/glide)将图像从谷歌加载到imageView,然后我从imageview抓取drawable。但在这种情况下,我没有得到正常的bitmapDrawable我得到一个不包含.toBitmap()函数的colorDrawable。这导致我出现问题,因为我需要保存位图。

所以问题是我可以将colorDrawable转换为位图吗?

此外,如果您有更好的方法从谷歌保存图像,您会将我链接到评论中的图像吗?我们可以留下主要问题的实际答案。

1 个答案:

答案 0 :(得分:0)

您可以存储图像视图图形缓存中的位图。

iv.buildDrawingCache();
Bitmap bitmap=iv.getDrawingCache();