Skip navigation.
 
mlRe: how 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:34:08 2006

On Aug 11, 2006, at 11:28 PM, Jonathan Grynspan wrote:

> Try the following:
>
> NSImage *partOfImage(NSImage *input, NSRect targetRect) {
>     if (input) {
>         NSImage *output = [[NSImage alloc] initWithSize: targetRect.size];
>         [output lockFocus];
>         [input
>             drawAtPoint:    NSZeroPoint
>             fromRect:    targetRect
>             operation:    NSCompositeCopy
>             fraction:        1.0f];
>         [output unlockFocus];
>         return [output autorelease];
>     } else {
>         return nil;
>     }
> }


Thanks, I will.  I've been reading the lockFocus and the drawAtPoint 
stuff since I posted the first request, trying to put my brain around 
it.  This helps immensely!

Thanks
Chad

>
> -Jonathan Grynspan
>
> On 12-Aug-06, at 1:17 AM, Chad Leigh wrote:
>

>> 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
>>
>> _______________________________________________
>> MacOSX-dev mailing list
>> <email_removed>
>> http://www.omnigroup.com/mailman/listinfo/macosx-dev

>
> _______________________________________________
> MacOSX-dev mailing list
> <email_removed>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev