Re: TIFF Error?
Re: TIFF Error?
- Subject: Re: TIFF Error?
- From: "Louis C. Sacha" <email@hidden>
- Date: Tue, 22 Jun 2004 18:38:33 -0700
Hello...
I don't think there is an automatic way to accomplish it, since the
problem originates from the fact that the NSImage imageNamed: class
method checks in the main bundle for images.
A possible partial solution (that isn't tested, and which still
requires some manual effort on your part) could be something like
this:
/* typed in mail, some code copied from other stuff typed in mail,
untested, etc... */
@interface NSImage (NamedImageFromBundleRegistration)
+ (BOOL)registerImageWithName:(NSString *)aName fromBundle:(NSBundle *)bundle;
@end
@implementation NSImage (NamedImageFromBundleRegistration)
+ (BOOL)registerImageWithName:(NSString *)aName fromBundle:(NSBundle *)bundle
/* returns FALSE if image can not be found in bundle or if there
already is an image registered with the same name */
{
NSString *imagePath = [bundle pathForImageResource:aName];
if (!imagePath) {return FALSE;}
else
{
NSImage *image = [[NSImage alloc]
initByReferencingFile:imagePath];
if (!image) {return FALSE;}
else
{
BOOL didName = [image setName:aName];
if (!didName)
{
/* there is already an image
registered with the same name */
[image release];
return FALSE;
}
}
}
return TRUE;
}
@end
Then in the initialize method of the primary class in your plugin:
+ (void)initialize
{
if (self == [YourClassName class])
{
/* ... */
NSBundle *pluginBundle = [NSBundle bundleForClass:self];
[NSImage registerImageWithName:@"YOURSomeImage"
fromBundle:pluginBundle];
[NSImage registerImageWithName:@"YOURAnotherImage"
fromBundle:pluginBundle];
/* ... and so on for all the images you are using
from the bundle ... */
}
}
The images will be loaded lazily as needed, although once they are
loaded they will remain in memory until the application quits. This
approach still requires some effort to keep everything updated since
you need to add a register message to the initialize method whenever
you add an image to your plugin project, but you shouldn't need to
set the images for the buttons manually since +imageNamed: will be
able to locate the images.
Hope that helps,
Louis
PS: You could also pose as NSImage and reimplement the imageNamed:
method to search all the bundles currently loaded, although overall
it would be quite inefficient to do it that way.
At 2:17 PM -0700 6/22/04, Louis C. Sacha wrote:
Have you tried reading in the TIFF and setting the button image
manually in your awakeFromNib method so that you can log what is
going on?
Yes, this is what I ended up doing, and it works, so I think the
error message just means that it can't find the image files
automatically. I would rather not have to do it manually, though, as
I may end up having quite a few images I need to load. Is there any
way to tell the OS, when controls from this .nib ask for images,
look in this bundle?
Thanks,
Darrin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.