如何在 Parse.com 上存储个人资料图片的 PNG 图像?
How to store PNG images for profile pictures on Parse.com?
我正在使用下面的代码注册一个用户,包括用户名、密码和个人资料照片。当个人资料图片是 JPG
时它有效,但当格式为“PNG”时 NOT。当我上传一张png图片时,图片是空白的。
我认为 JPG
有效,因为我正在使用此功能 UIImageJPEGRepresentation
。
我应该为 PNG 使用什么?
背景:This thread
func createUserwithAllFields() {
let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6)
//let profileImageData = UIImageJPEGRepresentation(profileImg, 0.6)
let profileImageFile = PFFile(data: profileImageData)
if tv_username.text != ""
&& tv_password.text != ""
{
var user = PFUser()
user.username = tv_username.text
user.password = tv_password.text
user["profileImage"] = profileImageFile
user.signUpInBackgroundWithBlock({ (success, error) -> Void in
if error == nil {
//if SignUp is successful
let installation = PFInstallation.currentInstallation()
installation["user"] = user
installation.saveInBackgroundWithBlock(nil)
//self.showChatOverview()
self.goToMainScreen()
} else {
}
})
}else{
}
}
使用函数 UIImagePNGRepresentation
而不是 UIImageJPEGRepresentation
应该可以解决问题![=13=]
let profileImageData = UIImagePNGRepresentation(profileAvatar.image, 0.6)
希望对你有帮助!
你说你想保存 png 图像,但你正在使用这个:
let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6)
UIImageJPEGRepresentation
不适用于保存 png 图像。使用 UIImagePNGRepresentation
。希望这有帮助..:)
我正在使用下面的代码注册一个用户,包括用户名、密码和个人资料照片。当个人资料图片是 JPG
时它有效,但当格式为“PNG”时 NOT。当我上传一张png图片时,图片是空白的。
我认为 JPG
有效,因为我正在使用此功能 UIImageJPEGRepresentation
。
我应该为 PNG 使用什么?
背景:This thread
func createUserwithAllFields() {
let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6)
//let profileImageData = UIImageJPEGRepresentation(profileImg, 0.6)
let profileImageFile = PFFile(data: profileImageData)
if tv_username.text != ""
&& tv_password.text != ""
{
var user = PFUser()
user.username = tv_username.text
user.password = tv_password.text
user["profileImage"] = profileImageFile
user.signUpInBackgroundWithBlock({ (success, error) -> Void in
if error == nil {
//if SignUp is successful
let installation = PFInstallation.currentInstallation()
installation["user"] = user
installation.saveInBackgroundWithBlock(nil)
//self.showChatOverview()
self.goToMainScreen()
} else {
}
})
}else{
}
}
使用函数 UIImagePNGRepresentation
而不是 UIImageJPEGRepresentation
应该可以解决问题![=13=]
let profileImageData = UIImagePNGRepresentation(profileAvatar.image, 0.6)
希望对你有帮助!
你说你想保存 png 图像,但你正在使用这个:
let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6)
UIImageJPEGRepresentation
不适用于保存 png 图像。使用 UIImagePNGRepresentation
。希望这有帮助..:)