• 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: Basic NSGraphicsContext question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic NSGraphicsContext question


  • Subject: Re: Basic NSGraphicsContext question
  • From: Gerard Iglesias <email@hidden>
  • Date: Sat, 5 Jul 2003 00:13:13 +0200

On Friday, July 4, 2003, at 10:36 PM, Jim Crafton wrote:

>> I think you probably want to look at the lockFocus and unlockFocus
>> methods of NSImage. Something like
>>
>> NSImage *myImage = [[NSImage alloc] initWithSize:NSMakeSize(width,
>> height)];
>>
>> [myImage lockFocus];
>>
>> // Draw here
>>
>> [myImage unlockFocus];
>>
>> will get you an NSImage that you can render to the window using the
>> various compositing and/or drawing methods.
>>
> Is it possible to get the NSGraphicsContext that the NSImage uses ?
> If not, is it possible to use the lower level Quartz 2D drawing API
> and still integrate nicely with Cocoa ?
> I was reading up on it, and Quartz has methods to create a bitmap GC,
> which is precisely what I want. However I am not sure how this
> corresponds to the Cocoa world.

Well, in fact when you create an NSImage you don't have any graphics
context attached to it, but when you do the lockFocus then the toolkit
create an offscreen window, a cached image, and then you are able to
get the current graphics context like this

NSImage *myImage = [[NSImage alloc] initWithSize:NSMakeSize(width,
height)];
CGContextRef ctx;

[myImage lockFocus];
ctx = [[NSGraphicsContext currentContext] graphicsPort];
// Draw here with CG function

[myImage unlockFocus];

I think that this stuff will work, don't have the time to test it...

Best regards

Gerard
_______________________________________________
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: Basic NSGraphicsContext question (From: Jim Crafton <email@hidden>)

  • Prev by Date: Re: Timers in a Foundation Tool
  • Next by Date: Re: Basic NSGraphicsContext question
  • Previous by thread: Re: Basic NSGraphicsContext question
  • Next by thread: Re: Basic NSGraphicsContext question
  • Index(es):
    • Date
    • Thread