This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo ImageManipulator iconExpo ImageManipulator

提供用于在本地文件系统上进行图片操作的 API 的库。

Android
iOS
tvOS
Web
Included in Expo Go
Recommended version:
~58.0.13

expo-image-manipulator 提供了一个 API 用于修改存储在本地文件系统中的图片。

安装

🌐 Installation

Terminal
- npx expo install expo-image-manipulator
- yarn expo install expo-image-manipulator
- pnpm expo install expo-image-manipulator
- bun expo install expo-image-manipulator

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

🌐 Usage

这将首先将图片顺时针旋转 90 度,然后垂直翻转旋转的图片并将其另存为 PNG。

🌐 This will first rotate the image 90 degrees clockwise, then flip the rotated image vertically and save it as a PNG.

Basic ImageManipulator usage
import { useEffect, useState } from 'react'; import { Button, Image, StyleSheet, Text, View } from 'react-native'; import { Asset } from 'expo-asset'; import { FlipType, SaveFormat, useImageManipulator } from 'expo-image-manipulator'; const IMAGE = Asset.fromModule(require('./assets/snack-icon.png')); export default function App() { const [imageUri, setImageUri] = useState(IMAGE.uri); const [isReady, setIsReady] = useState(false); const context = useImageManipulator(imageUri); const loadImageAsync = async () => { await IMAGE.downloadAsync(); setImageUri(IMAGE.localUri ?? IMAGE.uri); setIsReady(true); }; useEffect(() => { loadImageAsync(); }, []); const rotate90andFlip = async () => { context.rotate(90).flip(FlipType.Vertical); const renderedImage = await context.renderAsync(); const result = await renderedImage.saveAsync({ format: SaveFormat.PNG, }); setImageUri(result.uri); }; if (!isReady) { return ( <View style={styles.container}> <Text>Loading image...</Text> </View> ); } return ( <View style={styles.container}> <View style={styles.imageContainer}> <Image source={{ uri: imageUri }} style={styles.image} /> </View> <Button title="旋转和翻转" onPress={rotate90andFlip} /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', }, imageContainer: { marginVertical: 20, alignItems: 'center', justifyContent: 'center', }, image: { width: 300, height: 300, resizeMode: 'contain', }, });

应用接口

🌐 API

import * as ImageManipulator from 'expo-image-manipulator';

No API data file found, sorry!