Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 24, 2008, 08:57 AM   #1
DeDMakar
macrumors member
 
Join Date: Mar 2008
Send a message via ICQ to DeDMakar Send a message via Skype™ to DeDMakar
NSImageView setImage

I'm sorry if a basic question.
How to insert in NSImageView image? This code does not work:
Xcode:
@interface MyInitMainWindow : NSObject {
NSImage *StrIconUser;
IBOutlet NSImageView *IconUser;
}
-(IBAction)MySetImageid)sender;
@end

@implementation MyInitMainWindow
-(IBAction)MySetImageid)sender
{
[StrIconUser initWithContentsOfFile:@"~/Users/admin/Pictures/apple_big.jpg"];
[IconUser setImage:StrIconUser];
}
@end

Interface Builder:
IconUser outlets for NSImageView.
MySetImage action for NSButton.
DeDMakar is offline   0 Reply With Quote
Old Mar 24, 2008, 09:19 AM   #2
DeDMakar
Thread Starter
macrumors member
 
Join Date: Mar 2008
Send a message via ICQ to DeDMakar Send a message via Skype™ to DeDMakar
Link must be "/Users/admin/Pictures/apple_big.jpg" . Without ~ .
DeDMakar is offline   0 Reply With Quote
Old Mar 24, 2008, 09:23 AM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
The ~ character represents the user's home folder, which would be /Users/admin in your case. So the path would actually be ~/Pictures/apple_big.jpg, but in Cocoa ~ doesn't get translated, so you need to use the full path of /Users/admin/Pictures/apple_big.jpg
kainjow is offline   0 Reply With Quote
Old Mar 24, 2008, 09:35 AM   #4
CaptainZap
macrumors regular
 
Join Date: Jan 2007
You can convert a ~/ path to a full path by using this method
[@"~/" stringByExpandingTildeInPath];
__________________
CaptainZap is offline   0 Reply With Quote
Old Mar 25, 2008, 12:57 PM   #5
DeDMakar
Thread Starter
macrumors member
 
Join Date: Mar 2008
Send a message via ICQ to DeDMakar Send a message via Skype™ to DeDMakar
If my image is situated in the project folder, the full path may not be specified? Give example, please.
DeDMakar is offline   0 Reply With Quote
Old Mar 25, 2008, 01:28 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
The full path must always be specified. You just don't always have to hard code it into your app.

Look into the NSBundle, NSImage documentation. They provide everything you need to load images without needing to know the absolute path (if your image is inside your .app's Resources folder).
kainjow is offline   0 Reply With Quote
Old Mar 25, 2008, 01:58 PM   #7
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
Add the image to the project, in "Resources", and load the image using:

Code:
NSImage *theImage = [NSImage imageNamed:@"apple_big.jpg"];
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Mar 26, 2008, 09:32 AM   #8
DeDMakar
Thread Starter
macrumors member
 
Join Date: Mar 2008
Send a message via ICQ to DeDMakar Send a message via Skype™ to DeDMakar
Quote:
Originally Posted by Sayer View Post
Add the image to the project, in "Resources", and load the image using:

Code:
NSImage *theImage = [NSImage imageNamed:@"apple_big.jpg"];
Thank you.
DeDMakar is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
NSImage setImage? Blakeasd Mac Programming 4 Feb 4, 2011 12:00 PM
NSImageView vs Open GL Texture func iPhone/iPad Programming 0 Sep 16, 2009 06:49 AM
opening menu by clicking NSImageView xmax Mac Programming 3 Aug 19, 2009 09:47 AM
Single or Multiple NSImageViews Spike099 Mac Programming 7 Jun 29, 2007 06:46 PM
NSImage and NSImageView Problems Soulstorm Mac Programming 8 Dec 18, 2006 02:18 PM


All times are GMT -5. The time now is 09:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC