React native 在React Native中获取图像尺寸

React native 在React Native中获取图像尺寸,react-native,React Native,为什么这段代码会抛出错误?我用它来获取图像的尺寸 const { width, height } = Image.resolveAssetSource("Image-URL"); react\u native\u web\u dist\u exports\u Image\u WEBPACK\u IMPORTED\u MODULE\u 2\u默认值。resolveAssetSource不是函数 您正在使用的函数用于本地图像。如果您使用的是远程映像,则这将起作用: Image.

为什么这段代码会抛出错误?我用它来获取图像的尺寸

const { width, height } = Image.resolveAssetSource("Image-URL");
react\u native\u web\u dist\u exports\u Image\u WEBPACK\u IMPORTED\u MODULE\u 2\u默认值。resolveAssetSource不是函数


您正在使用的函数用于本地图像。如果您使用的是远程映像,则这将起作用:

Image.getSize(uri, success, failure)
例如:

Image.getSize(
    'https://link-to-image',
    (width, height) => {
        setWidth(width);
        setHeight(height);
    }
);

失败参数是什么?成功是成功获取图像时将执行的函数。如果失败,则将执行失败函数。