是否可以将Image.getSize与静态图像文件一起使用? [英] Is it possible to using Image.getSize with static image file?

查看:182
本文介绍了是否可以将Image.getSize与静态图像文件一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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 (来自

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与静态图像文件一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆