How to store PNG images for profile pictures on Parse.com?

150 views Asked by At

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{

}
}
2

There are 2 answers

0
Icaro On BEST ANSWER

Use the function UIImagePNGRepresentation instead UIImageJPEGRepresentation that should fix it!

let profileImageData =  UIImagePNGRepresentation(profileAvatar.image, 0.6)

I hope that helps you!

0
Rashad On

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.