Bringing image uploaded from ImagePicker to another view.

Hi, so I am new to SwiftUI and I have my image picker working on the ContentView and right now I want to select the photo library button and camera button and bring the image to a new page/viewer, but I cannot seem to find the coe for that. Does anyone know at string to do make that happen? Thank you!

// // ContentView.swift // test app // // Created by Bella L on 1/18/23. //

import SwiftUI

struct ContentView: View {       @State private var isShowPhotoLibrary = false   @State private var image = UIImage()   @Environment(.openURL) var openURL   @State private var selected: Bool = false       var body: some View {

    VStack {       //Link to website       Link(destination: URL(string:"")!, label: {         Text("Website")           .font(.system(size: 20))           .frame(width: 75, height: 50)           .foregroundColor(.white)           .background(Color("Dark"))           .cornerRadius(20)           .offset(x:125,y:1000)       })               //This is the text that is being labeled       Text("Welcome")         .foregroundColor(.black)         .offset(x:0,y:655)         .font(.system(size:30))       Text("Project")         .foregroundColor(.black)         .offset(x:0,y:670)         .font(.system(size:20))              //This is the logo image       Image("MainImage")         .resizable()         .scaledToFit()         .offset(x:0,y:250)         .frame(width: 300.0, height: 300.0)            //This begins the image picker and camera function       //This first one is the camera underneath       Image(uiImage: self.image)         .resizable()         .scaledToFill()         .frame(minWidth: 0, maxWidth: .infinity)         .edgesIgnoringSafeArea(.all)             Button(action: {         self.isShowPhotoLibrary = true       }) {         HStack {           Image(systemName: "camera")             .padding(.leading, -36.5)             .font(.system(size: 25))                       Text("Photo library")             .font(.headline)         }         .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 50)         .background(Color("Dark"))         .foregroundColor(.white)         .cornerRadius(20)         .padding(.horizontal)         .offset(x:0, y:-20)       }      //Right here begins the photo library and image picker       Image(uiImage: self.image)         .resizable()         .scaledToFill()         .frame(minWidth: 0, maxWidth: .infinity)         .edgesIgnoringSafeArea(.all)               Button(action: {         self.isShowPhotoLibrary = true       }) {         HStack {                       Image(systemName: "photo")             .font(.system(size: 25))                       Text("Camera")             .font(.headline)         }         .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 50)         .background(Color("Dark"))         .foregroundColor(.white)         .cornerRadius(20)         .padding(.horizontal)         .offset(x:0,y:-400)

      }     }     //This is where it actually begins to run the actual thing: This is the code that shows what happens when you are selecting an image     .sheet(isPresented: $isShowPhotoLibrary) {       ImagePicker(sourceType: .photoLibrary, selectedImage: self.$image)                    }          .sheet(isPresented: $isShowPhotoLibrary) {       ImagePicker(sourceType: .camera, selectedImage: self.$image)     }         }           struct ContentView_Previews: PreviewProvider {     static var previews: some View {       ContentView()     }   } }

Hello,

This code is rather difficult to read in this format, I'd recommend that you repost using Edit -> Paste and Match Style, which should format the code better.

Additionally, it looks like there is some missing info here, we do not have an "ImagePicker" api, so either this is your code not shown, or it's a 3rd party. In any case, I'd recommend that you adopt the PhotosPicker.

Bringing image uploaded from ImagePicker to another view.
 
 
Q