• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

图像而不是 UIImage 上传到 Firestore

用户头像
it1352
帮助1

问题说明

使用 Swift 5.0/SwiftUI 2.0

Using Swift 5.0 / SwiftUI 2.0

将 UIImage 上传到 Firestore 时可用的一种方法是 jpegData(compressionQuality: Double),它实质上使获取已保存图像的整个过程更快.

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.

是否有任何等效的 Image 或任何其他可行的解决方法,或者像 UIImage 或糟糕的 UX 一样简单

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,_March,_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)
    }
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfgabe
系列文章
更多 icon
同类精品
更多 icon
继续加载