我正在使用以下代码向用户注册用户名,密码和个人资料照片。当个人资料图片为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{
}
}
答案 0 :(得分:1)
使用应该修复它的UIImagePNGRepresentation
代替UIImageJPEGRepresentation
!
let profileImageData = UIImagePNGRepresentation(profileAvatar.image, 0.6)
我希望能帮到你!
答案 1 :(得分:0)
你说要保存png图像,但是你正在使用它:
let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6)
UIImageJPEGRepresentation
不用于保存png图像。使用UIImagePNGRepresentation
。希望这有助于.. :))