cts*_*tsu 9 android bitmap imageview
我尝试将Bitmap连接到ImageView,ImageView.getDrawingCache();但是我发现返回的Bitmap与我想从ImageView获取的不一样.它总是比真实的图像小.
我已经知道,getDrawingCache()如果该方法比屏幕大,则该方法不应具有视图,因为仅绘制视图的可见部分并且缓存仅保留绘制的内容.
我可以将整个位图附加到ImageView吗?
noo*_*oob 26
如果你只是想Bitmap从ImageView下面的代码可能会为你工作: -
Bitmap bm=((BitmapDrawable)imageView.getDrawable()).getBitmap();
Run Code Online (Sandbox Code Playgroud)
我想这就是你想要的.
mip*_*ble 14
如果您的drawble并不总是BitmapDrawable的实例
注意:在执行此操作之前,应先设置ImageView.
Bitmap bitmap;
if (mImageView.getDrawable() instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();
} else {
Drawable d = mImageView.getDrawable();
bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.draw(canvas);
}
Run Code Online (Sandbox Code Playgroud)
您的位图存储在位图中.
瞧!
| 归档时间: |
|
| 查看次数: |
23756 次 |
| 最近记录: |