• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving unseen NSView with subviews to NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving unseen NSView with subviews to NSImage


  • Subject: Re: Saving unseen NSView with subviews to NSImage
  • From: Rob Keniger <email@hidden>
  • Date: Tue, 30 Dec 2008 16:22:35 +1000


On 30/12/2008, at 4:11 PM, John Kestner wrote:

So am I right in believing that drawRect: should not need to be explicitly called in each subview from within my custom view's drawRect:? In any case, see if you can make sense of this...


Seems way too complicated to me. I have this in a category on NSView, which returns an NSImage of the view's content, including all subviews:

-(NSImage*) bitmapImageInRect:(NSRect) rect
{
NSBitmapImageRep* imageRep=[self bitmapImageRepForCachingDisplayInRect:rect];
NSGraphicsContext *previousContext = [NSGraphicsContext currentContext];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:imageRep]];
[[NSColor clearColor] set];
NSSize imageRepSize = [imageRep size];
NSRectFill(NSMakeRect(0, 0, imageRepSize.width, imageRepSize.height));
[NSGraphicsContext setCurrentContext:previousContext];
[self cacheDisplayInRect:rect toBitmapImageRep:imageRep];
NSImage* bitmapImage=[[NSImage alloc] initWithSize:rect.size];
[bitmapImage addRepresentation:imageRep];
return bitmapImage;
}


You could of course modify this to return the NSData from a - representationUsingType:properties: call on the NSBitMapImageRep.

--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Saving unseen NSView with subviews to NSImage (From: John Kestner <email@hidden>)
 >Re: Saving unseen NSView with subviews to NSImage (From: John Kestner <email@hidden>)
 >Re: Saving unseen NSView with subviews to NSImage (From: "I. Savant" <email@hidden>)
 >Re: Saving unseen NSView with subviews to NSImage (From: John Kestner <email@hidden>)
 >Re: Saving unseen NSView with subviews to NSImage (From: "I. Savant" <email@hidden>)
 >Re: Saving unseen NSView with subviews to NSImage (From: John Kestner <email@hidden>)

  • Prev by Date: Re: Help using NSAppleScript
  • Next by Date: Re: Notification when NSPersistentDocument done loading model
  • Previous by thread: Re: Saving unseen NSView with subviews to NSImage
  • Next by thread: Re: Saving unseen NSView with subviews to NSImage
  • Index(es):
    • Date
    • Thread