FROM : Matt Gough
DATE : Mon Apr 04 15:04:30 2005
On 4 Apr 2005, at 12:11, Ricky Sharp wrote:
>> I have N views (or more specifically, N subviews of a content view
>> that
>> holds M subviews with M >= N). I want to draw these N views into an
>> NSImage. I calculate the proper rect and initializes an NSImage
>> instance accordingly, i.e. its size matches that of the calculated
>> rect. I then do:
>>
>> [myImage lockFocus];
>> // fill the image with clearColor
>> // draw the N views via drawRect: calls
>> [myImage unlockFocus];
>>
>> This kinda works, i.e. I get an NSImage that almost looks right, but I
>> haven't been able to consistently have the N views draw so their
>> relative position to each other is kept. I have tried enough variants
>> of NSAffineTransform with -concat/-set (with and without
>> save/restoreGraphicsState) to realize that this may not be the way to
>> go. What is the recommended/preferred way to change the coordinate
>> system before each call to drawRect:?
>
> Check out the following sample:
>
> <http://developer.apple.com/samplecode/Color_Sampler/
> Color_Sampler.html>
>
> Specifically, look at NSView_snapshot.m which is a category on NSView
> that will generate an image of it. Simply lock focus on your
> top-level view and send it a snapshot message.
>
The problem with that is that you can only get stuff that is currently
actually displayed in the window that the view is in. I don't think you
can use it to just turn any view hierarchy into its equivalent image.
For that you need a combination of NSView's dataWithPDFInsideRect and
NSImage's initWithData.
Matt Gough
DATE : Mon Apr 04 15:04:30 2005
On 4 Apr 2005, at 12:11, Ricky Sharp wrote:
>> I have N views (or more specifically, N subviews of a content view
>> that
>> holds M subviews with M >= N). I want to draw these N views into an
>> NSImage. I calculate the proper rect and initializes an NSImage
>> instance accordingly, i.e. its size matches that of the calculated
>> rect. I then do:
>>
>> [myImage lockFocus];
>> // fill the image with clearColor
>> // draw the N views via drawRect: calls
>> [myImage unlockFocus];
>>
>> This kinda works, i.e. I get an NSImage that almost looks right, but I
>> haven't been able to consistently have the N views draw so their
>> relative position to each other is kept. I have tried enough variants
>> of NSAffineTransform with -concat/-set (with and without
>> save/restoreGraphicsState) to realize that this may not be the way to
>> go. What is the recommended/preferred way to change the coordinate
>> system before each call to drawRect:?
>
> Check out the following sample:
>
> <http://developer.apple.com/samplecode/Color_Sampler/
> Color_Sampler.html>
>
> Specifically, look at NSView_snapshot.m which is a category on NSView
> that will generate an image of it. Simply lock focus on your
> top-level view and send it a snapshot message.
>
The problem with that is that you can only get stuff that is currently
actually displayed in the window that the view is in. I don't think you
can use it to just turn any view hierarchy into its equivalent image.
For that you need a combination of NSView's dataWithPDFInsideRect and
NSImage's initWithData.
Matt Gough
| Related mails | Author | Date |
|---|---|---|
| Geert B. Clemmense… | Apr 4, 08:27 | |
| Ricky Sharp | Apr 4, 13:11 | |
| Matt Gough | Apr 4, 15:04 | |
| John C. Randolph | Apr 4, 20:13 | |
| Geert B. Clemmense… | Apr 5, 10:03 |






Cocoa mail archive

