Josh
2002.10.31, 01:26 PM
I have a class named ImageFrames that has two methods like this:
// In interface
NSImage *imageCache[2];
// in implementation
- (void)loadImage:(NSString *)path forFrame:(int)frame
{
imageCache[frame] = [[NSImage imageNamed:path] retain];
[imageCache[frame] setDataRetained:YES];
[imageCache[frame] lockFocus];
[imageCache[frame] unlockFocus];
if(imageCache[frame] == NULL)
{
NSLog(@"loadImage: image is null");
}
}
- (NSImage *)imageAtFrame:(int)frame
{
if(imageCache[frame] == NULL)
{
NSLog(@"frame num %d is null", frame);
}
return(imageCache[frame]);
}
And then I use it like so:
// in interface
ImageFrames *test;
// in awakeFromNib
test = [[ImageFrames alloc] init];
// in initWithFrame
[test loadImage:@"testImage" forFrame:1];
// in drawRect
[[test imageAtFrame:1] compositeToPoint:NSMakePoint(10, 10) operation:NSCompositeSourceOver];
I always get the message from -imageAtFrame that the image is null. I have tried using initWithContentsOfFile instead of imageNamed but it still doesn't work. Why?
// In interface
NSImage *imageCache[2];
// in implementation
- (void)loadImage:(NSString *)path forFrame:(int)frame
{
imageCache[frame] = [[NSImage imageNamed:path] retain];
[imageCache[frame] setDataRetained:YES];
[imageCache[frame] lockFocus];
[imageCache[frame] unlockFocus];
if(imageCache[frame] == NULL)
{
NSLog(@"loadImage: image is null");
}
}
- (NSImage *)imageAtFrame:(int)frame
{
if(imageCache[frame] == NULL)
{
NSLog(@"frame num %d is null", frame);
}
return(imageCache[frame]);
}
And then I use it like so:
// in interface
ImageFrames *test;
// in awakeFromNib
test = [[ImageFrames alloc] init];
// in initWithFrame
[test loadImage:@"testImage" forFrame:1];
// in drawRect
[[test imageAtFrame:1] compositeToPoint:NSMakePoint(10, 10) operation:NSCompositeSourceOver];
I always get the message from -imageAtFrame that the image is null. I have tried using initWithContentsOfFile instead of imageNamed but it still doesn't work. Why?