获取ImageView图片占用大小
时间: 2024-04-30 17:20:42 浏览: 17
你可以使用以下代码获取ImageView中显示的图片占用的大小:
```java
Drawable drawable = imageView.getDrawable();
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
int size = bitmap.getByteCount();
```
其中,`getDrawable()` 方法返回 `ImageView` 中显示的 `Drawable` 对象,如果该 `Drawable` 对象是 `BitmapDrawable` 类型的,则可以通过强制类型转换获取到其中的 `Bitmap` 对象。最后,可以使用 `getByteCount()` 方法获取该 `Bitmap` 对象占用的字节数,即图片占用的大小。
相关问题
android 获取imageview图片
获取 ImageView 图片,您需要使用以下代码:
ImageView imageView = findViewById(R.id.yourImageViewId);
Drawable drawable = imageView.getDrawable();
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ImageView 图片按照大小缩放
你可以使用 Android 中的 ScaleType 属性来控制 ImageView 中图片的缩放方式。常用的 ScaleType 包括 centerCrop、fitCenter、centerInside 等,具体使用方法可以参考 Android 官方文档。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)