设置使用iPhone相机拍摄的图像的types

如果我们使用iPhone相机拍摄照片,默认情况下,图像将以JPEG格式保存。

我想保存以PNG等其他格式捕获的图像。 可能吗?

当我们从我们的应用程序调用iPhone相机时,是否有可能从代码中做到这一点,我们可以设置捕获图片后,它必须保存的图像types? 我的意思是在拍照之前打开相机并设置types?

这将帮助你保存图像的PNGtypes

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo { NSError *error; NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@.png",@"photoname"]]; [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:NO]; NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSLog(@"Documents directory: %@", [fileManager contentsOfDirectoryAtPath:documentsDirectory error:&error]); [self dismissModalViewControllerAnimated:YES]; } 
 UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; // png image data NSData *pngData = UIImagePNGRepresentation(image); // jpeg image data NSData *jpegData = UIImageJPEGRepresentation(image, compressionQuality); // compressionQuality = 0.0 to 1.0 --> 0 means maximum compression and 1 means minimum compression 

一旦你获得NSData,你可以保存这个数据到特定的文件。 有关更多详情,请通过此链接

希望这会帮助你。

您可以在您的方法中使用类似于此的内容来将捕获的对象保存为PNG:

 // Create paths to output images NSString *thePngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Example.png"]; NSString *theJpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Example.jpg"]; // Write a UIImage to JPEG with minimum compression (best quality) // The value 'image' must be a UIImage object // The value '1.0' represents image compression quality as value from 0.0 to 1.0 [UIImageJPEGRepresentation(image, 1.0) writeToFile:theJpgPath atomically:YES]; // Write image to PNG [UIImagePNGRepresentation(image) writeToFile:thePngPath atomically:YES]; 

使用这个代码,

 NSData* pngdata = UIImagePNGRepresentation (image); //PNG wrap UIImage* img = [UIImage imageWithData:pngdata]; UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);