相同:
NSData*imageData =[image TIFFRepresentation];
NSBitmapImageRep*imageRep =[NSBitmapImageRep imageRepWithData:imageData];
[imageRep setSize:[[_imageView image] size]];
///////////png
imageData1 = [imageRep representationUsingType:NSPNGFileType properties:nil];
///////////jpg
NSDictionary *imageProps = nil;
NSNumber *quality = [NSNumber numberWithFloat:.85];
imageProps = [NSDictionary dictionaryWithObject:quality forKey:NSImageCompressionFactor];
imageData1 = [imageRep representationUsingType:NSJPEGFileType properties:imageProps];
写文件[imageData1 writeToFile:fileName atomically:YES];
最大的不同就是png文件没有设置属性,jpg文件设置了一些属性,这里设置的是压缩率,不知道是不是必需的,应该还有其他属性可以用来决定图片的质量。
NSImage 存储为jpg或png文件的方法,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/spiderdzl/p/3744083.html