问题描述
我想使用Image.getSize( https://facebook.github. io/react-native/docs/image.html )来获取图像的大小,但是第一个参数要求图像源位于URI中,但是我不能将URI与静态文件一起使用,只能使用需要.
I want to use Image.getSize (https://facebook.github.io/react-native/docs/image.html) to get the size of my image but the first argument require the image source to be in URI but I can't use URI with static file, I can only use Require.
因此,有可能在静态文件上使用Image.getSize还是我必须找到另一种方法?
Therefore, is it possible is to use Image.getSize on static file or do I have to find another way?
推荐答案
您可以使用 resolveAssetSource (来自 react-native/Libraries/Image/resolveAssetSource )以获取图像的大小.
You can use resolveAssetSource (from react-native/Libraries/Image/resolveAssetSource) to get the image's size.
import resolveAssetSource from 'resolveAssetSource';
和
let icon = require('./assets/images/icon.png');
let source = resolveAssetSource(icon);
// source.width, source.height`
这篇关于是否可以将Image.getSize与静态图像文件一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!