如何使用cocoa将JPEG图像转换为PICT图像。下面给出了一些脚本。
NSData *imgData = [NSData datawithContentsOfFile:@"/var/root/Desktop/1.jpeg"];
NSPICTImageRep *imagerep = [NSPICTImageRep imageRepWithData:imgData];
NSData *data = [imageRep PICTRepresentation];
[data writeTofile:@"/var/root/Desktop/save.pict" atomically:No];
此脚本不起作用。以及在没有Applescript的情况下将jpeg图像转换为pict图像的任何其他替代方法。
答案 0 :(得分:1)
您的代码存在一些问题。
#1)你是某些的位置" 1.jpeg
"文件?
#2)您没有查看" writeToFile
"的错误结果。在我的机器上,我无法写入" /var/root
" 。目录
修复源路径和目标路径后,应将代码更改为以下内容:
NSData *imgData = [NSData datawithContentsOfFile:@"/Users/anuj/Desktop/1.jpeg"];
NSPICTImageRep *imagerep = [NSPICTImageRep imageRepWithData:imgData];
NSData *data = [imageRep PICTRepresentation];
NSLog(@"my image data size is %ld", [data length]);
if([data length] > 0)
{
BOOL success = [data writeTofile:@"/Users/anuj/Desktop/save.pict" atomically:NO];
if(success)
NSLog(@"successfully wrote the file");
else
NSLog(@"did not write the file");
}
else
{
NSLog(@"didn't convert the image to a Pict");
}