Skip navigation.
 
mlhow to get a sub piece of an NSImage or make a new NSImage that is a subset of an existing one
FROM : Chad Leigh
DATE : Sat Aug 12 07:17:40 2006

I have a Cocoa app and I get a PDF image over the internet that I 
store in an NSImage using

    label = [[NSImage alloc] initWithData:finalImage];


The image previously was a PNG image and was exactly the image 
needed.  Now that they pass a PDF image, they pass an image that is 
an image of a complete piece of paper with the image I am interested 
in placed on the upper half of this virtual paper (the rest is just 
blank).  The image is always in the same place and the same size so I 
can determine a Rect that will always work to select it.  I want to 
extract this image out of the PDF and create a new NSImage (or 
overwrite the old one, I don't care) that I can use later on to print 
in my own existing print routine and to display thumbnails of it.

I do not see how to go about it.  Most of the draw/composite routines 
I see in NSImage rely on an existing userspace to draw into.  I want 
to "draw" into a new NSImage.  My brain is having a hard time 
adjusting to think about how to do this.

Ideally I want something like

   NSImage *newImage = [[NSImage alloc] initFromImage:oldImage 
usingRect:targetRect];

I expect what I want to do is very easy but if someone could point me 
on the way I should be exploring I would appreciate it.


Thanks
Chad