I am using the code below to sign up a user with username, password, and a profile picture. WHen the profile picture is a JPG
it works but NOT when the format is 'PNG`. WHen I upload a png image, the image is blank.
I think JPG
is working because I am using this function UIImageJPEGRepresentation
.
What should I be using for PNG?
Background: 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{
}
}
Use the function UIImagePNGRepresentation
instead UIImageJPEGRepresentation
that should fix it!
let profileImageData = UIImagePNGRepresentation(profileAvatar.image, 0.6)
I hope that helps you!
You said you want to save png image but you are using this:
let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6)
UIImageJPEGRepresentation
is not for saving png image. use UIImagePNGRepresentation
. Hope this helps.. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.