1

How to convert JPEG image to PICT image using cocoa.Some script is given below.

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];

This script is not work. and any other alternate method which convert jpeg image to pict image without Applescript.

.

4

1 回答 1

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");
}
于 2014-05-09T05:00:29.517 回答