【问题标题】:How to store PNG images for profile pictures on Parse.com?如何在 Parse.com 上存储个人资料图片的 PNG 图像?
【发布时间】:2015-06-11 05:00:01
【问题描述】:

我正在使用下面的代码注册用户,并使用用户名、密码和个人资料图片。当个人资料图片为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{

}
}

【问题讨论】:

  • 前几天我对它很好奇,我能够使用我发布的解决方案使其工作!
  • @Icaro sweet... 现在看起来很明显应该已经搜索过了。在我被解雇之前会试一试。
  • 现在我们知道了,我花了很长时间才弄清楚第一次!
  • 它对你有用吗?让我知道它是怎么回事,如果确实如此,请不要忘记将答案标记为已解决:) 谢谢
  • @Icaro 是的,它有效,谢谢。将您的答案标记为答案,它是第一个。

标签: ios xcode swift parse-platform uiimage


【解决方案1】:

使用应该修复它的函数UIImagePNGRepresentation 而不是UIImageJPEGRepresentation

let profileImageData =  UIImagePNGRepresentation(profileAvatar.image, 0.6)

希望对你有帮助!

【讨论】:

    【解决方案2】:

    你说你想保存 png 图片,但你正在使用这个:

    let profileImageData =  UIImageJPEGRepresentation(profileAvatar.image, 0.6)
    

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

    【讨论】:

      猜你喜欢
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 2023-03-28
      • 2019-10-17
      相关资源
      最近更新 更多