从ImageView获取位图

时间:2020-02-03 20:40:47

标签: android bitmap imageview

我知道这个问题已经被问过很多次了,但是每次我尝试从ImageView中检索位图时,它都会返回空对象

我尝试过:

ImageView imageView = findViewById(R.id.image);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); 

还有

imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();

还有滑行。

我是否缺少某些东西,或者还有其他方法可以实现?

感谢帮助

1 个答案:

答案 0 :(得分:1)

尝试一下,希望对您有帮助

ImageView imageView = findViewById(R.id.image);
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
Bitmap b = bd.getBitmap();