繁体   English   中英

使用解析SDK保存图像

[英]Saving an Image using Parse SDK

拍摄图像:

我正在使用此问题中的代码获取图像:使用UIIImagePicker的CGAffineTransform缩放UIImage并保存到Parse SDK

将UIImage转换为NSData并保存

    _imageData = UIImageJPEGRepresentation(_image, .1);
    PFFile *imageFile = [PFFile fileWithName:@"image.png" data:_imageData];
    newMessage[@"image"] = imageFile;

问题:

当我重新下载数据时,UIImage看上去被压缩了。 当我查看数据库中的图像时,似乎高度和宽度是相反的。 不知道为什么会这样...

NSData *imageData = UIImageJPEGRepresentation(yourImage, 1.0);
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:imageData];

    PFObject *userPhoto = [PFObject objectWithClassName:@"Photo"];
    [userPhoto setObject:imageFile forKey:@"image"];

    // Set the access control list to current user for security purposes
    userPhoto.ACL = [PFACL ACLWithUser:[PFUser currentUser]];

    [userPhoto setObject:user forKey:@"user"];

    [userPhoto saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!error) {
            NSLog(@"sucess");
        }
        else{
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        [[ConnectionManager sharedManager] removeload];
    }];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM