Просто используйте следующий код, и вы получите .tiff image
. Вы должны добавить ImageIO
и MobileCoreServices
Frameworks в ваш проект.
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/UTCoreTypes.h>
- (void)viewDidLoad {
[super viewDidLoad];
[self convertImageIntoTIFF];
}
-(void)convertImageIntoTIFF{
UIImage *img = [UIImage imageNamed:@"image.png"];
float compression = 1.0; // Lossless compression if available.
int orientation = 1; // Origin is at top, left.
CFStringRef myKeys[3];
CFTypeRef myValues[3];
CFDictionaryRef myOptions = NULL;
myKeys[0] = kCGImagePropertyOrientation;
myValues[0] = CFNumberCreate(NULL, kCFNumberIntType, &orientation);
myKeys[1] = kCGImagePropertyHasAlpha;
myValues[1] = kCFBooleanTrue;
myKeys[2] = kCGImageDestinationLossyCompressionQuality;
myValues[2] = CFNumberCreate(NULL, kCFNumberFloatType, &compression);
myOptions = CFDictionaryCreate( NULL, (const void **)myKeys, (const void **)myValues, 3,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSLog(@"documentsDirectory %@", documentsDirectory);
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"image.tiff"];
[self writeCGImage:img.CGImage toURL:[NSURL fileURLWithPath:filePath] withType:kUTTypeTIFF andOptions:myOptions];
}
- (void) writeCGImage: (CGImageRef) image toURL: (NSURL*) url withType: (CFStringRef) imageType andOptions: (CFDictionaryRef) options
{
CGImageDestinationRef myImageDest = CGImageDestinationCreateWithURL((CFURLRef)url, imageType, 1, nil);
CGImageDestinationAddImage(myImageDest, image, options);
CGImageDestinationFinalize(myImageDest);
CFRelease(myImageDest);
}
Для более подробной информации, вы можете скачать этот DemoCode .
Надеюсь, это то, что вы ищете. :)