Reputation: 33725
I have the following code:
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}} />;
But the code crashes because imgSrc is null. How do I get the width and height of a base64 encoded image such that I can use it in my <Image style={} />
element?
Upvotes: 4
Views: 4832
Reputation: 2409
Get dimensions by the following way works for me.
import { Image } from 'react-native';
Image.getSize(`data:image/png;base64,${img}`, (width, height) => {console.log(width, height)});
Upvotes: 5