我需要以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];
有没有办法 COMPRESS 图像(使文件数据更小),以便最大限度地减少块到达目的地的时间?
答案 0 :(得分:0)
您正在使用UIImagePNGRepresentation
创建UIImage
对象的文件表示形式。这将生成带有照片的大文件。尝试将JPEG文件格式与UIImageJPEGRepresentation
一起使用,并调整压缩质量以减小文件大小。