我试过了
if let uploadData = UIImageJPEGRepresentation(uploadImage, 0.9){
let subFileName = NSUUID().uuidString
storageRef.child("\(subFileName)").putData(uploadData, metadata: nil, completion: { (data , error) in
if error != nil{
print(error!)
}
})
我也试过
UIImagePNGRepresentation(uploadImage)
两者都没有产生原始质量的图像,唯一改变的是firebase存储的大小......我也尝试用cgSize更改来改变图像
func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage {
let size = image.size
let widthRatio = targetSize.width / image.size.width
let heightRatio = targetSize.height / image.size.height
var newSize: CGSize
if(widthRatio > heightRatio) {
newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
} else {
newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
}
let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
image.draw(in: rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
然而这一切都没有帮助:(我该如何解决这个问题?
我知道图像质量不好,因为当我从firebase控制台的下载URL加载它时质量很差..感谢您的帮助!!