2

在我的应用程序中,如果用户从相机胶卷中选择图像用作公司徽标(添加到最终 pdf 中),在某些情况下,它可以将附件大小从 8mb(无图像)变为 29mb。当用户通过电子邮件发送文件时,这是一个问题,因为它比大多数服务器都允许附件大小

- (IBAction)schemeLogoPressed:(id)sender {
 LogCmd();
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = NO;
    [self.editController presentModalViewController:imagePicker animated:YES];
   }    

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
    DebugLog(@"info dict: %@", info);
    [picker dismissModalViewControllerAnimated:YES];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    self.schemeLogo.backgroundColor = [UIColor whiteColor];
    self.schemeLogo.image = image;
    NSData *imageData1 = UIImagePNGRepresentation(image);
    NSString *path1 = [ICUtils pathForDocument:@"schemeLogo.png"];
    [imageData1 writeToFile:path1 atomically:NO];

我能做些什么来优化挑选的图像尺寸吗?

4

1 回答 1

5

更改此行:

NSData *imageData1 = UIImagePNGRepresentation(image);

至:

NSData *imageData1 = UIImageJPEGRepresentation(image, 0.9f);

第二个参数(0.9 float)是质量。数量更多,质量更高。从 0.0 到 1.0

于 2013-05-09T11:11:28.360 回答