• 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: How to show CGImageRef over an overlay nswindow.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to show CGImageRef over an overlay nswindow.


  • Subject: Re: How to show CGImageRef over an overlay nswindow.
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 29 Nov 2007 18:16:22 +0000

On 29 Nov 2007, at 12:29, Amit8 J wrote:

Hello all,
I am stuck to a problem related to core graphics. Actually i want to
display an image over a overlay nswindow. For creating an cgimageref i
have written the following code:

[snip]

You're going about this the hard way.  What you need to do is:

1. Create your NSWindow.

2. Add an NSImageView to the new window (e.g. by doing - setContentView:). You'll want to configure it as well (e.g. set the frame style, image alignment and image scaling properties).

3. Use NSImage to load the file (no need to use CGImage; that's just complicating matters). You should be able to do [NSImage imageNamed:@"originalColor.png"] to do this. (Compare with the code I chopped out.)

4. Send your NSImageView a -setImage: message to change its image.

Also, I don't think you need to subclass the window. Generally when you're writing Cocoa programs, you only subclass when you absolutely have to; this is quite a contrast to many other OO frameworks (particularly the Windows-based ones) where you tend to end up subclassing things all the time.

Anyway, most of the code you put into your NSWindow subclass could go into a method that creates and sets up the window and the image view.

The other thing that you perhaps didn't understand is that in Cocoa, you do your drawing in an NSView subclass's -drawRect:. Normally, anyway. So if you wanted to do the actual drawing yourself, you'd need to write a view that draws an image in its -drawRect:. Since this is a very common requirement, unsurprisingly there is already such a view (NSImageView), so there's no need to bother in this case... you can just use the ready-built one.

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

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: 
 >How to show CGImageRef over an overlay nswindow. (From: Amit8 J <email@hidden>)

  • Prev by Date: Re: Storing NSColor & NSData objects in an XML document
  • Next by Date: Re: Selections in NSCollectionView
  • Previous by thread: How to show CGImageRef over an overlay nswindow.
  • Next by thread: NSTableView - Leopard - Tooltips
  • Index(es):
    • Date
    • Thread