Re: imageNamed cannot load an image
Re: imageNamed cannot load an image
- Subject: Re: imageNamed cannot load an image
- From: Artemiy Pavlov <email@hidden>
- Date: Wed, 21 Mar 2007 23:24:18 +0200
On 21 Mar 2007, at 10:46 PM, Christopher Hickman wrote:
NSImage *BackgroundImage = [NSImage imageNamed:@"SpaceOscillator"];
Try using @"SpaceOscillator.png"
From
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/Clas
ses/NSImage_Class/Reference/Reference.html:
When looking for files in the application bundle, it is better (but
not
required) to include the filename extension in the name parameter.
When
naming an image with the setName: method, it is also convention not to
include filename extensions in the names you specify. That way, you
can
easily distinguish between images you have named explicitly and
those you
want to load from the application's bundle.
Thanks, I just tried this:
NSString* BackgroundImageName = [[NSBundle mainBundle]
pathForResource:@"SpaceOscillator.png" ofType:@"PNG"];
NSImage* BackgroundImage = [[NSImage alloc]
initWithContentsOfFile:BackgroundImageName];
and this:
NSString* BackgroundImageName = [[NSBundle mainBundle]
pathForResource:@"SpaceOscillator" ofType:@"PNG"];
NSImage* BackgroundImage = [[NSImage alloc]
initWithContentsOfFile:BackgroundImageName];
And in both cases BackgroundImage is nil...
Are there any extra steps except for dragging an image file into the
"Resources" in the XCode project, i.e.:
Attachment:
Picture 1.png
Description: application/applefile
The image shows up in the IB as "SpaceOscillator" and I can paste it
into the view, it will work, but I want to render it as a background.
Thanks very much,
Artemiy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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