reactjs - 调整大小后获取实际图像大小 React Native
问题描述
我正在从尺寸未知的 API 中获取图像。
我希望能够在调整大小过程后知道图像的实际大小。
<Image
style={{ resizeMode: Image.resizeMode.contain}}
source={{uri:'https://blabla.com/img.jpg'}}
/>
Image.resizeMode.contain是对图像进行统一缩放,使图像的两个尺寸(宽度和高度)都等于或小于视图的相应尺寸。
解决方案
您可以使用onLayout
<Image
style={{ resizeMode: Image.resizeMode.contain}}
source={{ uri:'https://blabla.com/img.jpg' }}
onLayout={(event) => {
const { width, height } = event.nativeEvent.layout;
console.log(`Image size: ${width}x${height}`);
}}
/>
推荐阅读
- spring-boot - okta认证后的404页面
- python - Hdf5 文件中未显示的列
- python - 如何在 Python 中仅询问 MadLib 中故事所需的变量
- javascript - 如何在使用 JavaScript 加载页面后在用户点击的特定 li 上添加活动类
- go - 无法编组 protobuf 结构
- python - 限制六个随机数,使三个负数和三个正数等于 1?
- php - PHP 开发服务器在响应正文中返回 HTTP 标头
- java - Thymeleaf HashMap 请求绑定
- javascript - 在 Array 中获取高于平均值的值 - JS
- java - 加密解密异或