在Iphone上有两种读取图片数据的简单方法: UIImageJPEGRepresentation和UIImagePNGRepresentation. UIImageJPEGRepresentation函数需要两个参数:图片的引用和压缩系数.而UIImagePNGRepresentation只需要图片引用作为参数.通过在实际使用过程中,比较发现: UIImagePNGRepresentation UIImage* image) 要比UIImageJPEGRepresentation(UIImage* image, 1.0) 返回的图片数据量大很多.譬如,同样是读取摄像头拍摄的同样景色的照片, UIImagePNGRepresentation
** 在Iphone上有两种读取图片数据的简单方法 **UIImageJPEGRepresentation和UIImagePNGRepresentation.** UIImageJPEGRepresentation 函数需要两个参数:图片的引用和压缩系数而UIImagePNGRepresentation 只需要图片引用作为参数. UIImagePNGRepresentation(UIImage \*image) 要比UIImageJPEGRepresentation(UIImage* image, 1.0) 返回的图片数据量大很多 同样的一张照片, 使用UIImagePNGRepresentation(image) 返回的数据量大小为199K 而 UIImageJPEGRepresentation(image, 1.0)返回的数据量大小只为 data = UIImagePNGRepresentation(image); }else { // JPEG图像。
NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"image.png"]; [UIImagePNGRepresentation NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"image.png"]; [UIImagePNGRepresentation NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"ss.png"]; [UIImagePNGRepresentation
二、图片压缩的实现 2.1 “压”处理 对于“压”的功能,我们一般是使用系统提供的UIImageJPEGRepresentation或UIImagePNGRepresentation方法实现,如: 只需要传一个参数,就是图片对象 NSData *imgData = UIImagePNGRepresentation(image); UIImagePNGRepresentation要比UIImageJPEGRepresentation 同样的一张照片, 使用UIImagePNGRepresentation(image)返回的数据量大小为199K,而UIImageJPEGRepresentation(image, 1.0)返回的数据量大小只为 UIImagePNGRepresentation虽然可以让我们控制压缩质量比例,但是我们看到这个压缩比compressionQuality实际上很难确定一张图片是否能压缩到误差范围内,无法实现精确压缩。 2.2 “缩”处理 UIImagePNGRepresentation虽然可以让我们控制压缩质量比例,但是我们看到这个压缩比compressionQuality实际上很难确定一张图片是否能压缩到误差范围内
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; NSData *data; if (UIImagePNGRepresentation data = UIImageJPEGRepresentation(image, 1.0); } else { data = UIImagePNGRepresentation
break; } }]; ##单个文件上传 UploadParam *uploadParam = [[UploadParam alloc] init]; uploadParam.data = UIImagePNGRepresentation @"/file/upload"]; ##多任务上传 UploadParam *uploadParam = [[UploadParam alloc] init]; uploadParam.data = UIImagePNGRepresentation uploadParam.mimeType = @"image/png"; UploadParam *uploadParam1 = [[UploadParam alloc] init]; uploadParam1.data = UIImagePNGRepresentation
error) { NSLog(@"获取服务器响应出错"); }]; } @第二种: NSData *imageData = UIImagePNGRepresentation
stringByAppendingPathComponent:[NSString stringWithFormat:@"sms.jpg"]]; // 保存文件的名称 BOOL result = [UIImagePNGRepresentation
//将image的data加入 UIImage*image = [UIImage imageNamed:@"1212312.png"]; NSData *imageData = UIImagePNGRepresentation
存储速度:JPG更快 压缩比:JPG更大; 图片质量:JPG更好 JPG不支持透明效果; UIImageJPEGRepresentation方法在耗时上比较少 而UIImagePNGRepresentation 耗时操作时间比较长; UIImageJPEGRepresentation函数需要两个参数:图片的引用和压缩系数.而UIImagePNGRepresentation只需要图片引用作为参数.通过在实际使用过程中 ,比较发现: UIImagePNGRepresentation(UIImage* image) 要比UIImageJPEGRepresentation(UIImage* image, 1.0) 返回的图片数据量大很多 .譬如,同样是读取摄像头拍摄的同样景色的照片, UIImagePNGRepresentation()返回的数据量大小为199K ,而 UIImageJPEGRepresentation(UIImage* NSData并进行压缩 http://www.cnblogs.com/robinkey/archive/2013/01/21/2869930.html UIImageJPEGRepresentation和UIImagePNGRepresentation
- (void)saveImage:(UIImage *)tempImage WithName:(NSString *)imageName { NSData * imageData = UIImagePNGRepresentation
constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { NSData *data = UIImagePNGRepresentation
[documentPath stringByAppendingPathComponent:@"my.png"]; //创建data 暂存图片 NSData *imageData =UIImagePNGRepresentation
1.3 PNG与JPEG优劣比较 存储速度:JPG更快 压缩比:JPG更大; 图片质量:JPG更好 JPG不支持透明效果; UIImageJPEGRepresentation方法在耗时上比较少 而UIImagePNGRepresentation 耗时操作时间比较长 UIImageJPEGRepresentation函数需要两个参数:图片的引用和压缩系数.而UIImagePNGRepresentation只需要图片引用作为参数.通过在实际使用过程中 ,比较发现:UIImagePNGRepresentation(UIImage* image) 要比UIImageJPEGRepresentation(UIImage*image, 1.0) 返回的图片数据量大很多 .譬如,同样是读取摄像头拍摄的同样景色的照片, UIImagePNGRepresentation()返回的数据量大小为199K ,而 UIImageJPEGRepresentation(UIImage* CGSizeMake(25.0f,35.0f)] 1.5 参考链接 IOS-图片操作集合 http://blog.csdn.net/ch_soft/article/details/7685753 UIImagePNGRepresentation
self.imageView.image == nil) return; // 有图片才继续执行 // 通过蓝牙链接会话发送数据到所有设备 [self.session sendDataToAllPeers:UIImagePNGRepresentation
NSString *)directoryPath { if ([[extension lowercaseString] isEqualToString:@"png"]) { [UIImagePNGRepresentation
(NSString )directoryPath { if ([[extension lowercaseString] isEqualToString:@"png"]) { [UIImagePNGRepresentation
(imageFormat == SDImageFormatPNG); } if (usePNG) { imageData = UIImagePNGRepresentation UIImage decodedAndScaledDownImageWithImage:image]; [self.imageData setData:UIImagePNGRepresentation
INSpeakableString alloc] initWithSpokenPhrase:@"珲少"]; // 联系人图片 INImage *image = [INImage imageWithImageData:UIImagePNGRepresentation
if (user.picture2) { NSData *data = UIImagePNGRepresentation