[英]react-native get image dimensions of base64 image
我有以下代码:
let imgSrc =resolveAssetSource("data:image/png;base64,"+img);
console.log(imgSrc);
let img = <Image source={{uri:"data:image/png;base64,"+img}} style={{width:imgSrc.width/2, height:imgSrc.height/2}} />;
但是代码崩溃了,因为 imgSrc 为空。 如何获取 base64 编码图像的宽度和高度,以便可以在我的<Image style={} />
元素中使用它?
通过以下方式获取尺寸对我有用。
import { Image } from 'react-native';
Image.getSize(`data:image/png;base64,${img}`, (width, height) => {console.log(width, height)});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.