2009-10-27 45 views
4

我在Mac OSX上产生32×32平方的位图图形编辑可可应用程序写入图像到一个文件,我需要以编程方式(我不能使用界面生成器的话)输出此图片.jpg或.png。任何人都可以将我链接到一些关于如何完成这项任务的好资源?在可可应用

+1

我们需要知道更多。目前如何在内部存储这些数据?你在Mac OS X或iPhone上? – 2009-10-27 22:11:26

回答

3

如果从图像中,可以产生PNG和JPEG获得一个NSBitmapImageRep。请参阅representationUsingType:properties:

+0

但你如何得到一个NSImage中的NSBitImageRep? – Mike2012 2009-11-11 00:59:38

2

我知道你说过jpeg或png,但是你可以使用NSImageTIFFRepresentation方法。它返回一个NSData的实例。所以沿着这条线做点什么

[[yourImageInstance TIFFRepresentation] writeToFile:@"/path/to/file.tiff" atomically:NO]; 

会把TIFF图像写入文件。我不认为NSImage在PNG或JPEG格式获取数据的任何内置的方式。

编辑

做了一个快速谷歌和发现this link与信息上保存PNG数据,而不是TIFF数据。看起来非常简单。

2

具有的UIImage称为图像:

NSData *imageData = UIImageJPEGRepresentation(image, 1.0); 
NSString *tmpPathToFile = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/tempImage.jpg", tempPath]]; 
[imageData writeToFile:tmpPathToFile atomically:YES]; 
0

使用适用于iPhone的PhotoshopFrameworkhttps://sourceforge.net/projects/photoshopframew/)。有非常方便的方法将图像保存到磁盘:

/// Save as JPG File with High Quality. 
-(BOOL)saveAsJPGFile:(NSString*)anFileName; 

/// Save as JPG File with User Defined Quality. 
-(BOOL)saveAsJPGFile:(NSString*)anFileName compressionQuality:(CGFloat)quality; 

/// Save as PNG File. 
-(BOOL)saveAsPNGFile:(NSString*)anFileName;