我想要做的图像是在图像视图出现在屏幕上之前获得它的形状。
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"/>
我这样做了,但图像视图没有出现,因为在图像加载之前高度是wrap_content。图像在上传后会扩展,但我想在不加载图像的情况下获取图像大小。
发布于 2018-06-07 17:11:51
我假设您正在从服务器获取图像URL /路径。比如,http://.....。
然后,通过将图像转换为位图,您肯定会从其路径/ URL中获得图像的高度和宽度。
试试这个:
try {
URL url = new URL("http://....");// here put your string URL comes from server
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
int width = b.getWidth(); // here is the your image width
int height = b.getHeight(); // here is the your image height
} catch(IOException e) {
System.out.println(e);
}
https://stackoverflow.com/questions/50736898
复制相似问题