gpt4 book ai didi

ios - 优化从相机胶卷中选取的图像以减小文件大小

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:30:23 26 4
gpt4 key购买 nike

在我的应用程序中,如果用户从相机胶卷中选择一张图像用作公司 Logo (添加到最终的 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];

我可以做些什么来优化选取的图像大小吗?

最佳答案

改变这一行:

NSData *imageData1 = UIImagePNGRepresentation(image);

到:

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

第二个参数(0.9 float )是质量。数字越大,质量越高。从 0.0 到 1.0

关于ios - 优化从相机胶卷中选取的图像以减小文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16460211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com