• 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: NSImage - newbie
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage - newbie


  • Subject: Re: NSImage - newbie
  • From: Steven Noyes <email@hidden>
  • Date: Sun, 11 Mar 2007 08:32:14 -0700

A few ways:

1) An NSImageView in your app. This will accept dragged in images if you want.

2) The methods "initWithContentsOfFile:" "initWithData:";

3) the class method "+imageNamed". This might be what you are doing now.

Using a file open and loading the files is straight forward:

----------------------------------------------
//
//	Open sheet routines
//
- (void)didEndOpenSheet:(NSOpenPanel *)openPanel
             returnCode:(int)returnCode
            contextInfo:(void *)contextInfo
{
    int			index;
    NSArray		*files;
    NSMutableArray	* newImages;
    NSImage		*newFrame;

    [openPanel orderOut:nil];
    [openPanel setDelegate:nil];

if (returnCode == NSOKButton)
{
files = [openPanel filenames];
newImages = [NSMutableArray arrayWithCapacity:100];
for (index = 0; index < [files count]; index++)
{
newFrame = [[NSImage alloc] initWithContentsOfFile: [files objectAtIndex:index]];
if (newImage != nil)
{
[newImages addObject:newFrame];
[newFrame release];
}
}


	//
	// save the images to someplace to be used.
	//
	[self setImages:newImages];

//
// Save the defaults for the next time NTUserDefaults is a convenience class of mine.
//
[NTUserDefaults setDefaultOpenDirectory:[openPanel directory]];
}
}


- (IBAction)addFile:(id)sender
{
    NSOpenPanel	*panel = [NSOpenPanel openPanel];
    NSArray	*allFiles = [NSArray arrayWithObjects:
        @"tiff",
        @"tif",
        @"jpeg",
        @"jpg",
        nil];

[panel setAllowsMultipleSelection:YES];
[panel beginSheetForDirectory:[NTUserDefaults defaultOpenDirectory]
file:nil
types:allFiles
modalForWindow:parentWindow
modalDelegate:self
didEndSelector:@selector (didEndOpenSheet:returnCode:contextInfo:)
contextInfo:nil];
}



----------------------------------------------

On Mar 11, 2007, at 1:32 AM, Wayne Melrose wrote:

Hi,

I'm fumbling my way through a sample project I've downloaded, I find sample code a really great way to learn. In saying that, I'm stuck, and I'm trying to look at documentation on how to load an image, which isn't part of the project.

QUESTION.
What is the best way to load an image into an NSImage view using the full path to an image. (That is not stored in the app.)?


I'm new to cocoa so I'm finding it all a little too much at the moment.

Thanks in advance for any help.




--------------------------------------------------------- Wayne Melrose email@hidden www.waynemelrose.net


_______________________________________________

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

_______________________________________________

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


References: 
 >NSImage - newbie (From: Wayne Melrose <email@hidden>)

  • Prev by Date: [solved] Re: Coredata performance problem : massive insertion produces error in allocate region
  • Next by Date: Re: Need help with setNeedsDisplay - Another Update
  • Previous by thread: Re: NSImage - newbie
  • Next by thread: Coredata performance problem : massive insertion produces error in allocate region
  • Index(es):
    • Date
    • Thread