我正在将具有透明背景的图像上传到 Firebase。当我以某种方式下载它时,背景变白了。知道如何解决这个问题吗?
这是我的 putData 函数。
let uploadData = imageview.image!.jpegData(compressionQuality: 0.75)
let uploadTask = imagesRef.putData(uploadData!, metadata: nil, completion: { (metadata, error) in
guard let metadata = metadata else {
return
}
这里是下载函数。
URLSession.shared.dataTask(with: NSURL(string: imageURL as! String)! as URL, completionHandler: { (data, response, error) -> Void in
if error != nil {
print("ERROR LOADING IMAGES FROM URL: \(String(describing: error))")
DispatchQueue.main.async {
imageView.image = UIImage()
}
return
}
DispatchQueue.main.async {
if let downloadedImage = UIImage(data: data!) {
imageCache.setObject(downloadedImage, forKey: NSString(string: imageURL!))
imageView.image = downloadedImage
}
}
}).resume()
最佳答案
I'm uploading an image with a transparent background to firebase. The background becomes white when I downloaded it somehow. Any idea how to fix this?
您做对了,除了您得到的是 JPEG 而不是 PNG 数据;)请记住 JPEG 不支持透明 BG。
希望对您有所帮助!
关于ios - 透明背景变白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53862030/