• 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
NSBitmapImageRep subclass problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSBitmapImageRep subclass problem


  • Subject: NSBitmapImageRep subclass problem
  • From: Alan Hart <email@hidden>
  • Date: Fri, 7 Apr 2006 19:03:54 +0100

Hi

I'm trying to add .pcx image file handling to my app, and as far as I can tell NSBitmapImageRep doesn't know about .pcx files. So I have written code to create an NSBitmapImageRep from the .pcx file data and then used addRepresentation: to attach it to an NSImage. That works, and I can then manipulate and composite the images as I expect.

However, I'd really prefer to do it using a PCXImageRep class, defined and registered as a subclass of NSBitMapImageRep, since it seems that's the way the Cocoa image architecture ought to work. Then it would be available to read a .pcx file anywhere in my app, and it would be more reusable elsewhere.

So I have:

@interface MyPCXImageRep : NSBitmapImageRep {}
@end

@implementation MyPCXImageRep

+(void) load {
	[NSImageRep registerImageRepClass:[MyPCXImageRep class]];
}

+ (NSArray *)imageUnfilteredFileTypes {
	static NSArray *types = nil;
	if (!types)
		types = [NSArray arrayWithObjects:@"pcx", @"PCX", nil];
	return types;
}

- (BOOL) canInitWithData {
	return YES;
}

+ (id)imageRepWithContentsOfFile:(NSString*)file {
	NSData* data = [NSData dataWithContentsOfFile:file];
	if (data)
		return [MyPCXImageRep imageRepWithData:data];
	return nil;
}

+ (id)imageRepWithData:(NSData*)pcxData {
	/* code to extract image parameters from the data */

MyPCXImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: <parameters> ] autorelease];

if (imageRep) {
/* code to populate the pixel map */
}
return imageRep;
}
@end


I provided both imageRepWithData: and imageRepWithContentsOfFile: as it's not clear which gets called.

The load and imageUnfilteredFileTypes methods are called, and I can then see the correct responses to the messages:
[NSImageRep registeredImageRepClasses] and [NSImageRep imageFileTypes].


But [[NSImage alloc] initWithContentsOfFile:pcxFile] never calls either of my imageRepWith ... methods, and returns nil.

I guess maybe I have to override other NSBitmapImageRep methods, but I can't see which, and the documentation seems a bit vague on subclassing NSImageRep. I'd appreciate any suggestions as to what I'm doing wrong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: NSBitmapImageRep subclass problem
      • From: Daniel Vollmer <email@hidden>
    • Re: NSBitmapImageRep subclass problem
      • From: Nicko van Someren <email@hidden>
  • Prev by Date: Re: nubie: help return an object from another class
  • Next by Date: Re: Annoying ToolTip difficulty
  • Previous by thread: Re: Annoying ToolTip difficulty
  • Next by thread: Re: NSBitmapImageRep subclass problem
  • Index(es):
    • Date
    • Thread