【问题标题】:Get actual image size, after resizing it React Native调整大小后获取实际图像大小 React Native
【发布时间】:2018-05-21 10:26:19
【问题描述】:

我正在从尺寸未知的 API 获取图像。

我希望能够知道调整大小后图像的实际大小。

            <Image 
            style={{ resizeMode: Image.resizeMode.contain}}
            source={{uri:'https://blabla.com/img.jpg'}} 
            />

Image.resizeMode.contain是对图像进行统一缩放,使图像的两个尺寸(宽和高)都等于或小于视图对应的尺寸。 p>

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    您可以使用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}`);
        }} 
    />
    

    【讨论】:

    • 谢谢,它对我有用,但你应该将最后一个 ) 更改为 }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    相关资源
    最近更新 更多