• 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: Drawing a view inside an image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing a view inside an image


  • Subject: Re: Drawing a view inside an image
  • From: Olivier <email@hidden>
  • Date: Tue, 10 Dec 2002 10:10:44 -0600

You need to have the view inside a window to be able to focus the view.
I'm trying to do exactely the same thing as you are.
I put my progress indicator in window that i created programatically.

that create an image, but that image does not contain the progress
indicator...


windowContainingIndicator = [[NSWindow alloc]
initWithContentRect: NSMakeRect(0, 0, 100, 100)

styleMask: NSBorderlessWindowMask

backing: NSBackingStoreNonretained

defer: NO];
indicator = [[NSProgressIndicator alloc] initWithFrame:
NSMakeRect(0, 0, 16, 16)];
[[windowContainingIndicator contentView] addSubview: indicator];
[indicator setDoubleValue: 0];
[indicator setMinValue: 0];
[indicator setMaxValue: 100];

the style of the progress indicator is set somewhere else, and i make
sure to set is display when stopped to YES, but no luck yet, let me
know if you find a solution

olivier

On Monday, December 9, 2002, at 08:39 PM, Simone Manganelli wrote:

> I was using init, and then I was using the setFrame: method
> immediately after, but apparently it still didn't work.
>
> I tried to modify my code to use the method you used below, but now
> I'm getting some uncaught exceptions. Here's the new code:
>
> NSProgressIndicator *theProgressIndicator;
> NSBitmapImageRep *rep;
> NSImage *theNewImage = [[NSImage alloc]
> initWithSize:NSMakeSize(60,12)];
> NSRect theRect = NSMakeRect(0,0,60,12);
> [theProgBarImage release];
> theProgressIndicator = [[NSProgressIndicator alloc]
> initWithFrame:theRect];
> [theProgressIndicator setIndeterminate:NO];
> [theProgressIndicator setMaxValue:[theMaxValue doubleValue]];
> [theProgressIndicator setDoubleValue:[memUsage doubleValue]];
> [theProgressIndicator stopAnimation:nil];
> [theProgressIndicator lockFocus];
> rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:theRect];
> [theProgressIndicator unlockFocus];
> [theNewImage addRepresentation:rep];
> [rep release];
> [theProgressIndicator release];
> theProgBarImage = theNewImage;
>
> I'm getting this set of errors:
>
> 2002-12-09 18:34:15.881 MyApp[18892] *** Assertion failure in
> -[NSProgressIndicator lockFocus], AppKit.subproj/NSView.m:2343
> 2002-12-09 18:34:15.885 MyApp[18892] An uncaught exception was raised
> 2002-12-09 18:34:15.895 MyApp[18892] lockFocus sent to a view whose
> window is deferred and does not yet have a corresponding platform
> window
> 2002-12-09 18:34:15.895 MyApp[18892] *** Uncaught exception:
> <NSInternalInconsistencyException> lockFocus sent to a view whose
> window is deferred and does not yet have a corresponding platform
> window
>
> MyApp has exited due to signal 5 (SIGTRAP).
>
> Any help?
>
> -- Simone Manganelli
>
> On Monday, Dec 9, 2002, at 16:58 US/Pacific, John C. Randolph wrote:
>
>>
>> On Monday, December 9, 2002, at 01:12 PM, Simone Manganelli wrote:
>>
>>> How would one go about drawing the image of an NSView into an
>>> NSImage? Specifically, I want to draw what a specific
>>> NSProgressIndicator looks like into a specific NSImage, which I then
>>> want to use in my program. How would one go about doing that? I've
>>> tried it using this code:
>>>
>>> NSProgressIndicator *theProgressIndicator;
>>> NSImage *theProgBarImage = [[NSImage alloc]
>>> initWithSize:NSMakeSize(60,12)];
>>> NSRect theRect = NSMakeRect(0,0,60,12);
>>> [theProgBarImage lockFocus];
>>> theProgressIndicator = [[NSProgressIndicator alloc] init];
>>
>> [snippage]
>>
>>>
>>> However, it doesn't seem to work. What am I doing wrong?
>>
>> You're calling -init, instead of -initWithFrame: when you create your
>> progress indicator. The designated initializer for any NSView
>> subclass is -initWithFrame. The effect of this is that the progress
>> indicator never created the cell it should use to draw its contents.
>>
>> BTW, I wrote a category of NSImage a while ago that does this:
>>
>> @implementation NSView (snapshot)
>>
>> - (NSImage *) snapshot { return [self snapshotFromRect:[self
>> bounds]]; }
>> - (NSImage *) snapshotFromRect:(NSRect) sourceRect;
>> /*"This method creates a new image from a portion of the receiveing
>> view. The image is returned autoreleased."*/
>> {
>> NSImage
>> *snapshot = [[NSImage alloc] initWithSize:sourceRect.size];
>>
>> NSBitmapImageRep
>> *rep;
>>
>> [self lockFocus];
>> rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:sourceRect];
>> [self unlockFocus];
>>
>> [snapshot addRepresentation:rep];
>> [rep release];
>> return [snapshot autorelease]; // balance the +alloc call..
>> }
>>
>> @end
>>
>>
>> It's part of the "Color Sampler" example, available at:
>>
>> http://developer.apple.com/samplecode/Sample_Code/Cocoa/
>> Color_Sampler.htm
>>
>> -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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Drawing a view inside an image
      • From: Olivier <email@hidden>
References: 
 >Re: Drawing a view inside an image (From: Simone Manganelli <email@hidden>)

  • Prev by Date: Re: [OT] Opinions on EOF / Suggestions for diploma thesis
  • Next by Date: Dumb App Quitting Questoin
  • Previous by thread: Re: Drawing a view inside an image
  • Next by thread: Re: Drawing a view inside an image
  • Index(es):
    • Date
    • Thread