优化从相机胶卷中挑选的图像以减小文件大小
Posted
技术标签:
【中文标题】优化从相机胶卷中挑选的图像以减小文件大小【英文标题】:Optimise image picked from camera roll to reduce file size 【发布时间】:2013-05-09 11:01:31 【问题描述】:在我的应用程序中,如果用户从相机胶卷中选择一张图像用作公司徽标(添加到最终 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];
我可以做些什么来优化选取的图像大小?
【问题讨论】:
【参考方案1】:改变这一行:
NSData *imageData1 = UIImagePNGRepresentation(image);
到:
NSData *imageData1 = UIImageJPEGRepresentation(image, 0.9f);
第二个参数(0.9 float)是质量。数量更多,质量更高。从 0.0 到 1.0
【讨论】:
正是我所追求的,简单明了,谢谢,加1!以上是关于优化从相机胶卷中挑选的图像以减小文件大小的主要内容,如果未能解决你的问题,请参考以下文章
如何避免将从相机胶卷中挑选的图像保存到相机胶卷? [iOS]