简体   繁体   English

透明背景变成白色

[英]Transparent background turns white

I'm uploading an image with a transparent background to firebase. 我正在将透明背景的图像上传到Firebase。 The background becomes white when I downloaded it somehow. 当我以某种方式下载时,背景变成白色。 Any idea how to fix this? 任何想法如何解决这个问题?

Here's my putData function. 这是我的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
    } 

And here is the download function. 这是下载功能。

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. 我正在将透明背景的图像上传到Firebase。 The background becomes white when I downloaded it somehow. 当我以某种方式下载时,背景变成白色。 Any idea how to fix this? 任何想法如何解决这个问题?

You're doing it right, except you're getting getting a JPEG instead of PNG data ;) Remember that JPEG does not support transparent BG. 您做对了,只是要获取JPEG而不是PNG数据;)请记住,JPEG不支持透明BG。

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM