问题
Using Swift 5.0 / SwiftUI 2.0
One method available when uploading an UIImage to Firestore is jpegData(compressionQuality: Double) which essentially makes the whole process of fetching the saved image a lot faster.
Is there any equivalent for Image yet or any other viable workarounds or its as simple as either UIImage or poor UX
回答1:
struct ContentView: View {
//Here
@State var uiImage: UIImage?
var body: some View {
VStack {
if uiImage != nil {
Image(uiImage: uiImage!)
}
Button(action: {
downloadImage()
}, label: {
Text("Download image")
})
}
}
func downloadImage() {
URLSession.shared.dataTask(with:URL(string: "https://upload.wikimedia.org/wikipedia/commons/3/3f/Self-portrait_taken_with_laptop%2C_March%2C_2018.jpg")!) { (data, response, eooror) in
guard data != nil else { return }
DispatchQueue.main.async {
self.uiImage = UIImage(data: data!)
}
}.resume()
}
//Here
func getData() {
var data = uiImage?.jpegData(compressionQuality: 0.5)
}
}
来源:https://stackoverflow.com/questions/65614931/uploading-an-image-instead-of-an-uiimage-to-firestore