从 ImageView 获取位图

nic*_*er 2 android bitmap imageview

我知道这个问题以前被问过很多次,但每次我尝试从 ImageView 检索位图时,它都会返回 null 对象

我试过 :

ImageView imageView = findViewById(R.id.image);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); 
Run Code Online (Sandbox Code Playgroud)

imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)

而且还有滑行。

我错过了什么还是有其他方法可以实现这一目标?

感谢帮助

小智 5

试试这个,希望有帮助

ImageView imageView = findViewById(R.id.image);
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
Bitmap b = bd.getBitmap();
Run Code Online (Sandbox Code Playgroud)