在Android中获取位图的尺寸而不读取整个文件

前端之家收集整理的这篇文章主要介绍了在Android中获取位图的尺寸而不读取整个文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@
我想在 Android获取位图的尺寸而不读取整个文件.

我尝试使用推荐的inJustDecodeBounds和记录read()的自定义InputStream.不幸的是,基于此,Android BitmapFactory似乎读取了大量字节.

相近:
适用于Android的Java/ImageIO getting image dimensions without reading the entire file?,不使用ImageIO.

解决方法

你是正确的使用inJustDecodeBounds.将其设置为true并确保在解码中包含选项.这只是读取图像大小.

无需读取流.只需在解码中指定路径即可.

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(<pathName>,options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
原文链接:https://www.f2er.com/android/316767.html

猜你在找的Android相关文章