NSImage representations [fixed]
NSImage representations [fixed]
- Subject: NSImage representations [fixed]
- From: Ryan Stevens <email@hidden>
- Date: Sun, 13 Jun 2004 18:57:34 -0700
I didn't search or ask the list for the answer since I could work
around it easily enough but it should be in the archives if it's not
already.
I was trying to save a mutli-rep NSImage but the reps were getting
rearranged on me. [image representations] was ordered how I wanted but
saving the TIFFRepresentation resulted in a file where the reps were
ordered largest to smallest by -size (undocumented feature?).
This was just a quickie to get me on my way. [Insert standard
disclaimer]
Use -TIFFData in place of -TIFFRepresentation
NSRect RectFromSize(NSSize size) {
NSRect rect;
rect.origin = NSZeroPoint;
rect.size = size;
return rect;
}
@implementation NSImage (WorkAround)
- (NSData *)TIFFData
{
NSArray *reps = [[self representations] retain];
NSEnumerator *enumerator = [reps objectEnumerator];
id rep = nil;
NSSize largestSize;
NSSize repSize;
while (rep = [enumerator nextObject]) {
repSize = [rep size];
if (!NSEqualSizes(largestSize, repSize)) largestSize =
NSUnionRect(RectFromSize(largestSize), RectFromSize(repSize)).size;
[self removeRepresentation:rep];
}
enumerator = [reps objectEnumerator];
while (rep = [enumerator nextObject]) {
repSize = [rep size];
if (!NSEqualSizes(largestSize, repSize)) {
NSRect repRect = RectFromSize(repSize);
NSImage *tmp = [[NSImage alloc] initWithSize:largestSize];
NSImage *tmp0 = [[NSImage alloc] initWithSize:repSize];
[tmp0 addRepresentation:rep];
[tmp lockFocus];
[tmp0 drawInRect:repRect fromRect:repRect
operation:NSCompositeSourceOver fraction:1];
[tmp unlockFocus];
[self addRepresentation:[[tmp representations]
objectAtIndex:0]];
[tmp release];
[tmp0 release];
} else [self addRepresentation:rep];
}
[reps release];
return [self TIFFRepresentation];
}
@end
_______________________________________________
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.