• 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: John Kestner <email@hidden>
  • Date: Tue, 30 Dec 2008 01:11:15 -0500

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...


// This is in my controller:
- (IBAction) saveAllVisualizations: (id)sender
{
NSRect pRect = NSMakeRect(0, 0, 480, 640);
PlantView *pView = [[PlantView alloc] initWithFrame: pRect];
NSManagedObjectContext *context = [[NSApp delegate] managedObjectContext];

NSFetchRequest *fetchAllPersons = [[NSFetchRequest alloc] init];
[fetchAllPersons setEntity: [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context]];

for (PersonMO *p in [context executeFetchRequest:fetchAllPersons error:nil])
{
[pView save:p];
}
}


// This is in my custom view:
- (IBAction) save: (id) sender
{
	NSString *personName = [sender name];

NSRect pRect = NSMakeRect(0, 0, 480, 640);
NSBitmapImageRep* offscreenRep = nil;
offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:pRect.size.width
pixelsHigh:pRect.size.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:0
bytesPerRow:(4 * pRect.size.width)
bitsPerPixel:32];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep]];


	[self drawRect:pRect];

NSString *fileName = [NSString stringWithFormat: @"~/Desktop/%@.jpg", personName];
NSString *filePath = [fileName stringByExpandingTildeInPath];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat:1.0], NSImageCompressionFactor, nil];

NSData *data = [offscreenRep representationUsingType:NSJPEGFileType properties:dict];
[data writeToFile:filePath atomically:YES];

[NSGraphicsContext restoreGraphicsState];
}




On Dec 29, 2008, at 4:53 PM, I. Savant wrote:

On Mon, Dec 29, 2008 at 4:41 PM, John Kestner <email@hidden> wrote:
Yep, they're actual subviews nested in my custom view, double- checked by
going to list view in IB.

You may need to post your "Save All Visualizations" code. This is hard to "visualize" without it (pun intended).

_______________________________________________

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


  • Follow-Ups:
    • Re: Saving unseen NSView with subviews to NSImage
      • From: "Michael Ash" <email@hidden>
    • Re: Saving unseen NSView with subviews to NSImage
      • From: Rob Keniger <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>)

  • Prev by Date: Re: respondsToSelector - #import OR compiler warnings?
  • Next by Date: Re: Help using NSAppleScript
  • 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