Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to show CGImageRef over an overlay nswindow.



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >How to show CGImageRef over an overlay nswindow. (From: Amit8 J <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.