Re: Question about opening file
Re: Question about opening file
- Subject: Re: Question about opening file
- From: Chris Gehlker <email@hidden>
- Date: Sun, 07 Oct 2001 21:36:35 -0700
On 10/7/01 8:45 PM, "John Tsombakos" <email@hidden> wrote:
>
I'm playing around with a sample application that I built, using
>
instructions I found on the web (somewhere, I can't for the life of me
>
remember where!) It's a document based application that just has an
>
NSImageView in the window. You can open an image and it gets displayed
>
in the window. Simple enough.
>
>
The tutorial told how to set up the files extensions in the targets pane
>
of the project to include jpg files. Today, I tried changing it to be
>
able to also open tiff files. I tried adding another file type and
>
rebuilt and ran. It would not let me select a tiff file in the Open
>
dialog. I tried removing the jpg selection and rebuilding. I even did a
>
clean and rebuild but could not open a tiff file. I decided to try
>
changing it back to jpg and cleaned and rebuilt. Now I can't open either
>
tiff or jpg!
Here is a little code fragment that will open any kind of picture. Sorry
about the formatting:
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
result = [oPanel runModalForDirectory:[NSHomeDirectory()
stringByAppendingPathComponent:@"Pictures"]
file:nil types:[NSImage imageFileTypes]];
if (result == NSOKButton) {
myImage = [[NSImage alloc] initByReferencingFile:[oPanel filename]];
...
The trick here is [NSImage imageFileTypes] which returns an NSArray of every
type that QuickTime understands, or may understand in the future. It rocks.
--
Many individuals have, like uncut diamonds, shining qualities beneath a
rough exterior. - Juvenal, poet (c. 60-140)