如何通过转换为bytecode64将图像发送到API?

时间:2019-12-20 12:16:26

标签: swiftui nodeapi

这是我的代码,我想将图像发送到API。我需要转换图像的帮助,我也应该从哪里获得图像。

我正在使用SwiftUI开发一个应用程序。我有一个已由用户加载的图像。我想在用户界面中显示其尺寸。如何从保存在此图片中的图片中获取这些尺寸?

struct T4View: View {

    @State private var showImagePicker: Bool = false
    @State private var image: Image? = nil
    @State private var cimage: String = ""

    var body: some View {
        VStack {
            image?.resizable()
                .scaledToFit()
            Button("Open Camera") {
                self.showImagePicker = true   
            }   .padding()
                .background(Color.green)
                .foregroundColor(Color.white)
                .cornerRadius(10)
                .frame(width: 250, height:150)
            Button(action: {
                // What to perform
                let url = URL(string: "http://192.168.2.160:9090/sendDataToImage?CapturedImage='"+self.cimage+"'")!
                 //print(url)
                 URLSession.shared.dataTask(with: url) {(data,response,error) in
                     do {
                         if let d = data {
                             //let decodedLists = try JSONDecoder().decode([QCapi].self, from: d)
                             var e = error
                             if e == nil {
                                 print("success")
                                  // self.showingAlert=true;
                             } else {
                                 print("Wrong username password")
                                 //self.showingAlert=true;
                                 //self.x=true
                             }
                         } else {
                             print("No Data")
                         }
                     } catch {
                         print ("Error")
                     }
                 }   .resume()
            }) {
                Spacer()
                Text("SEND IMAGE")
                    .frame(width: 70, height:100)
                //            Spacer()
                Spacer()
            }   .padding(EdgeInsets(top: 8, leading: 10, bottom: 8, trailing: 10))
                .frame(width: 200, height:50)
                .background(Color.green)
                .foregroundColor(Color.white)
                .cornerRadius(10)   
        }   .sheet(isPresented: self.$showImagePicker) {
            PhotoCaptureView(showImagePicker: self.$showImagePicker, image: self.$image)   
    }
}

struct T4View_Previews: PreviewProvider {
    static var previews: some View {
        //verifyOTP()
        // BottomNav()
        T4View()
    }
}      
}

0 个答案:

没有答案