Resizing images
The width
and height
style properties of Image
components determine the size of what’s rendered on the screen. For example, you’ll probably have to work with images at some point that have a larger resolution than you want to be displayed in your React Native application. Simply setting the width
and height
style properties on the Image
is enough to properly scale the image.
Let’s look at some code that lets you dynamically adjust the dimensions of an image using controls:
export default function App() {
const source = require("./assets/flux.png");
const [width, setWidth] = useState(100);
const [height, setHeight] = useState(100);
return (
<View style={styles.container}>
<Image source={source} style={{ width, height }} />
<Text>Width: {width}</Text>
<Text>Height: {height}</Text>
<Slider
style={styles.slider}
minimumValue={50}
maximumValue...