0

我需要以 512 字节的块将图像发送到服务器。

我得到的图像是:

- (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];

有没有办法压缩图像(使文件数据更小)以最小化块到达目的地的时间?

4

1 回答 1

0

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

于 2014-09-23T13:01:56.197 回答