【问题标题】:Setting the image property of a PFImageView to a local image, then updating Parse database with the PFFile将 PFImageView 的图像属性设置为本地图像,然后使用 PFFile 更新 Parse 数据库
【发布时间】:2014-09-04 14:00:31
【问题描述】:

PFImageView 及其.file 属性及其对应的-loadInBackground 方法非常有用。我无法弄清楚如何“走另一条路”,即从新图像中获取 PFFile 参考:

RA_MyAccount.h(摘录)

@property (weak, nonatomic) IBOutlet PFImageView *profilePic;
-(IBAction)saveButtonTapped:(id)sender;

RA_MyAccount.m(摘录)

-(void)setLocalImageToPFImageView:(UIImage *)localImage
{
    self.profilePic.image = localImage
}

-(IBAction)saveButtonTapped:(id)sender
{
    PFUser *cUser = [PFUser currentUser];

    // Get the PFFile reference for the new image
    PFFile *file;
    file = ??? ??? ??? ???

    // Set
    cUser[PF_USER_PIC] = file;

    [cUser saveInBackgroundWithBlock:
     ^(BOOL succeeded, NSError *error){
         [self performSegueWithIdentifier:@"unwindtotabviewsegue" sender:self];
     }];
}

我已经用??? ??? ??? ??? 指出了我遇到问题的地方。

【问题讨论】:

    标签: parse-platform pffile


    【解决方案1】:

    所以,我有一个答案,但我只是不相信这是最聪明的方法。当我对图像编码一无所知时,我也很担心开始使用像 UIImageJPEGRepresentation 这样的函数(它甚至是一个函数吗?)。

    file = [PFFile fileWithData:UIImageJPEGRepresentation(self.profilePic.image, 0.8f)];
    

    【讨论】:

      【解决方案2】:

      只要您对图像丢失质量没问题(如果是照片应该没问题),那么您想按照以下方式进行操作。 0.8 代表 80% 的压缩质量。

      file = [PFFile fileWithData:UIImageJPEGRepresentation(self.profilePic.image, 0.8f)];
      

      如果你不能失去质量,那么按照以下方式进行。

      file = [PFFile fileWithData:UIImagePNGRepresentation(self.profilePic.image)];
      

      请参阅this question,了解各种格式的更详细比较。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多