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.

.

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
A_kumar
  • 401
  • 1
  • 4
  • 12

1 Answers1

1

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");
}
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215