OK, here's my objective.. I want to take a screenshot of a section of the screen and then save it as a JPEG. Here's what I have...
NSBitmapImageRep *grabbedImage = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 534, 386, 298)];
NSData *grabbedImageData = [grabbedImage representationUsingType:NSJPEGFileType properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.0f] forKey:@"NSImageCompressionFactor"]];
[[NSFileManager defaultManager] createFileAtPath: [[NSString stringWithString: @"~/Desktop/newlycreatefile.jpg"] stringByExpandingTildeInPath] contents: grabbedImageData attributes: [NSDictionary dictionaryWithObjectsAndKeys:@""]];
In this first line I am making a NSBitmapImageRep by giving it the coordinates of the screen I want to take a picture of. Then I am turning it into an NSData which I then use as the contents of the file I create in the third line. However this doesn't work... It compiles fine... I hit the button.. no warnings... On the desktop there is newlycreatedfile.jpg, however the Finder reports it as being 0 KB. Now dragging it on Chimera tells me it can't be displayed due to errors. And OmniWeb gives a big clue:
Cannot Load Address
Not a JPEG file: starts with 0xff 0xd9
Which leads me to believe that I am generating a TIFF file (or at least something that identifies itself as a TIFF file but has no content). And sure enough, changing the file extension to .tiff and dragging it onto OmniWeb doesn't show this error (though it doesn't show anything at all... sense it is zero bytes).
So what can I do? Am I approaching this wrong? How can I make it
really a JPEG and have it actually have the data I put in there. Sorry for all the questions but I really need to get this working! Thanks
