Skip navigation.
 
mlRe: NSView to NSImage
FROM : Michael Watson
DATE : Tue Jul 18 00:40:49 2006

It really depends on what kind of data is being displayed in the 
views you're attempting to capture. NSBitmapRep doesn't seem to be 
able to see through all views and see all content types like -
dataWithPDFInsideRect: can.

> [view lockFocus];
> NSImage *image = [[NSImage alloc] initWithData:[view 
> dataWithPDFInsideRect:[view bounds]]];
> [view unlockFocus];


The view itself is returning a rendered PDF representation of the 
data within it and its subviews. NSBitmapImageRep seems to work 
differently, but I'm not quite sure how.

For most purposes, NSBitmapImageRep is sufficient (it's also faster, 
I believe), but occasionally you'll come across something that it 
can't capture. (QTMovieView, for example, will render blank white 
with NSBitmapImageRep, whereas NSView's -dataWithPDFInsideRect: will 
get the job done correctly.


--
Michael Watson


On 17 Jul, 2006, at 17:53, Tristan Jehan wrote:

> Michael,
>
> The "second" solution worked perfectly!
> The first didn't do the right thing, perhaps because my view wasn't 
> visible on screen...
>
> Thanks!
>
> Tristan

Related mailsAuthorDate
mlNSView to NSImage Tristan Jehan Jul 16, 22:47
mlRe: NSView to NSImage Michael Watson Jul 16, 22:56
mlRe: NSView to NSImage Tristan Jehan Jul 17, 23:53
mlRe: NSView to NSImage Michael Watson Jul 18, 00:40