• 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: Rendering an NSControl into a NSImage?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rendering an NSControl into a NSImage?


  • Subject: Re: Rendering an NSControl into a NSImage?
  • From: "John C. Randolph" <email@hidden>
  • Date: Tue, 1 Apr 2003 15:49:46 -0800

On Tuesday, April 1, 2003, at 03:33 PM, Mark Alldritt wrote:

This code does not compile because rep is undefined. I changed it to the
following -- I'm not sure if this is what you intended:

[snip]

Whoops!

Umm, no, that's not what I had in mind. (Mail.app is a lousy code editor ;-)

Try:

- (NSImage *) snapshotFromRect:(NSRect) sourceRect;
/*"This method creates a new image from a portion of the receiving view. The image is returned autoreleased."*/
{
NSImage
*snapshot = [[NSImage alloc] initWithSize:sourceRect.size];

[snapshot lockFocus];

[[NSColor clearColor] set]; // these two lines may be unnecessary.
NSRectFill(sourceRect);

[self drawRect:sourceRect];
[snapshot unlockFocus];
return [snapshot autorelease]; // balance the +alloc call..
}

the resultant image should end up containing one NSCachedImageRep. If you see strangeness that looks like coordinates getting munged, you might need to resort to using CG functions to make the current CG transform equivalent to that of the reciever.

-jcr


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Rendering an NSControl into a NSImage? (From: Mark Alldritt <email@hidden>)

  • Prev by Date: Re: Rendering an NSControl into a NSImage?
  • Next by Date: Newbie EXE_BAD_ACCESS Resolved
  • Previous by thread: Re: Rendering an NSControl into a NSImage?
  • Next by thread: Re: Rendering an NSControl into a NSImage?
  • Index(es):
    • Date
    • Thread