当前位置: 动力学知识库 > 问答 > 编程问答 >

sips - How to convert jpeg image to PICT image on MAC using Cocoa

问题描述:

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.

.

网友答案:

There's a couple problems with your code.

#1) are you certain of the location of that "1.jpeg" file?

#2) you're not looking at the error result of your "writeToFile". On my machine, I can not write to anything inside the "/var/root" directory.

Once you fix up the source and destination paths, you should change your code to something like this:

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");
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: