如何在Parse.com上存储个人资料图片的PNG图像?

时间:2015-06-11 05:00:02

标签: ios xcode swift parse-platform uiimage

我正在使用以下代码向用户注册用户名,密码和个人资料照片。当个人资料图片为JPG时,如果格式为“PNG”,则。当我上传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{

}
}

2 个答案:

答案 0 :(得分:1)

使用应该修复它的UIImagePNGRepresentation代替UIImageJPEGRepresentation

let profileImageData =  UIImagePNGRepresentation(profileAvatar.image, 0.6)

我希望能帮到你!

答案 1 :(得分:0)

你说要保存png图像,但是你正在使用它:

let profileImageData =  UIImageJPEGRepresentation(profileAvatar.image, 0.6)

UIImageJPEGRepresentation不用于保存png图像。使用UIImagePNGRepresentation。希望这有助于.. :))