2014-09-23 28 views
0

我需要将图像以512字节的块形式发送到服务器。如何压缩UIImage以便更快地将其发送到服务器

我刚刚接到图像:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
    [weakViewController dismissModalViewControllerAnimated:YES]; 

    UIImage *shareImage = info[UIImagePickerControllerEditedImage]; 
imageData = UIImagePNGRepresentation(shareImage); 

    imageURL = [[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString]; 


    imageURL = [NSString stringWithFormat:@"%@/%d.png",[StorageManager sharedManager].storagePath, (int)[[NSDate date] timeIntervalSince1970]]; 
    [imageData writeToFile:imageURL atomically:YES]; 

NSString *imageUri = [NSString stringWithFormat:@"%@/%d.jpg",[StorageManager sharedManager].storagePath, (int)[[NSDate date] timeIntervalSince1970]]; 
    [imageData writeToFile:imageUri atomically:YES]; 
} 

//获取图像

fileData = [[NSFileManager defaultManager] contentsAtPath:imageURL]; 

     file=[[message.fileURL pathComponents] lastObject]; 

有没有办法来COMPRESS图像(使FILEDATA更小),以尽量减少大块到达目的地的时间?

回答

0

您正在使用UIImagePNGRepresentation创建UIImage对象的文件表示形式。这将产生一个包含照片的大文件。尝试使用带有UIImageJPEGRepresentation的JPEG文件格式,并调整压缩质量以减小文件大小。

+0

你能用.jpeg重构我的代码吗?如果我从照片库中检索文件.jpeg,我可以大幅缩小文件大小吗?你能给我一个基于我发布的内容的例子吗?谢谢! – 2014-09-23 14:10:08

相关问题