• 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
NSImage representations [fixed]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Prev by Date: Re: _NSGetCarbonMenu question
  • Next by Date: Adding new menu items
  • Previous by thread: Hidden message
  • Next by thread: Adding new menu items
  • Index(es):
    • Date
    • Thread