我尝试在使用UIImageJPEGRepresentation上传到服务器之前压缩图像。
到目前为止,我已将图像更改为PNG并将质量更改为0.01f。我尝试了几种不同的写作方法。
在发送到服务器之前这是最佳的吗?我应该改变什么来优化?
- (void)uploadPhoto {
WUTModelImageUploadReq *imageUploadReq = [[WUTModelImageUploadReq alloc]init];
imageUploadReq.photo = [self encodeToBase64String:[UIImage imageWithData:UIImageJPEGRepresentation(self.viewControllerPost.imageForPost, 0.01f)]];
imageUploadReq.extension = @"png";
void (^wsSuccessHandler)(AFHTTPRequestOperation *operation, NSDictionary* responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"Pull Feed responseObject %@",responseObject);
NSError *error;
WUTModelPostImageResponse *wsResponse = [[WUTModelPostImageResponse alloc]initWithDictionary:(NSDictionary *)responseObject error:&error];
if (error) {
errorMessage = @"Failure to upload image.";
[self postExecuteFail];
}
else{
if (wsResponse.success) {
WUTModelImage *imageTemp = [wsResponse.data firstObject];
[postItem setObject:imageTemp.photo forKey:@"photo"];
[self uploadPostFeed];
}else{
errorMessage = @"Failure to upload image.";
[self postExecuteFail];
}
}
};
答案 0 :(得分:0)
建议: