--- title: Use an image picker --- import { SnackInline, Terminal } from '~/ui/components/Snippet'; import Video from '~/components/plugins/Video'; import { A } from '~/ui/components/Text'; import { Step } from '~/ui/components/Step'; import { BoxLink } from '~/ui/components/BoxLink'; import { BookOpen02Icon } from '@expo/styleguide-icons'; React Native provides built-in components that are standard building blocks used by every application, such as ``, ``, and ``. We want to build a feature that isn't possible with these core components and API: selecting an image from the device's media library. For that, we will need a library. To achieve this, we'll use an Expo SDK library called `expo-image-picker`. > `expo-image-picker` provides access to the system's UI to select images and videos from the phone's library or take a photo with the camera. ## Install expo-image-picker To install the library, run the following command: > **Tip:** Any time we install a new library in our project, we must stop the development server by pressing Ctrl + c in the terminal and then running the installation command. > After the installation, we can start the development server again by running `npx expo start` from the same terminal window. ## Pick an image from the device's media library `expo-image-picker` provides the `launchImageLibraryAsync()` method that displays the system UI for choosing an image or a video from the device's media library. We can use the button with the primary theme we created in the previous chapter to pick an image from the device's media library. We'll create a function to launch the device's image library to implement this functionality. In **App.js**, import the `expo-image-picker` library and create a `pickImageAsync()` function inside the `App` component: {/* prettier-ignore */} ```jsx App.js // ...rest of the import statements remain unchanged /* @info Import the ImagePicker. */ import * as ImagePicker from 'expo-image-picker'; /* @end */ export default function App() { const pickImageAsync = async () => { /* @info Pass image picker options to launchImageLibraryAsync() */ let result = await ImagePicker.launchImageLibraryAsync({ allowsEditing: true, quality: 1, }); /* @end */ if (!result.canceled) { /* @info If the image is picked, print its information in terminal window. */ console.log(result); /* @end */ } else { /* @info If the user does not picks an image, show an alert. */ alert('You did not select any image.'); /* @end */ } }; // ...rest of the code remains same } ``` Let's learn what the above code does. - The `launchImageLibraryAsync()` receives an object in which different options are specified. This object is an `ImagePickerOptions` object. We can pass the object to specify different options when invoking the method. - When `allowsEditing` is set to `true`, the user can crop the image during the selection process on Android and iOS but not on the web. ## Update the button component When the primary button gets pressed, we need to call the `pickImageAsync()` function. To call it, update the `onPress` property of the `