从 ImageView 获取位图
GetBitmap from ImageView
我知道这个问题以前被问过很多次,但每次我尝试从我的 ImageView 中检索位图时,它 return 空对象
我试过了:
ImageView imageView = findViewById(R.id.image);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
和
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
还有滑行。
我是不是遗漏了什么或者有其他方法可以做到这一点吗?
感谢帮助
试试这个,希望对你有帮助
ImageView imageView = findViewById(R.id.image);
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
Bitmap b = bd.getBitmap();
我有一个 kotlin 解决方案。
val bitmap = binding.myImageView.getDrawable().toBitmap()
希望对您有所帮助。
我知道这个问题以前被问过很多次,但每次我尝试从我的 ImageView 中检索位图时,它 return 空对象
我试过了:
ImageView imageView = findViewById(R.id.image);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
和
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
还有滑行。
我是不是遗漏了什么或者有其他方法可以做到这一点吗?
感谢帮助
试试这个,希望对你有帮助
ImageView imageView = findViewById(R.id.image);
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
Bitmap b = bd.getBitmap();
我有一个 kotlin 解决方案。
val bitmap = binding.myImageView.getDrawable().toBitmap()
希望对您有所帮助。