Re: Cocoa-dev Digest, Vol 6, Issue 1550
Re: Cocoa-dev Digest, Vol 6, Issue 1550
- Subject: Re: Cocoa-dev Digest, Vol 6, Issue 1550
- From: Dalmazio Brisinda <email@hidden>
- Date: Wed, 28 Oct 2009 17:06:01 -0600
On 2009-10-28, at 8:17 AM, email@hidden wrote:
On 28/10/2009, at 4:49 PM, Peter N Lewis wrote:
a) composite two images, preferably while keeping the different
resolutions of the icon
b) how to dim an image similarly to kTransformDisabled
I'm unclear what you mean by a), but certainly compositing NSImage
into another one or into a view/context is trivial.
An NSImage (potentially) contains multiple resolutions (eg 16x16,
128x128, 512x512). Especially if it is created from an IconRef.
What trivial way is there to take two NSImages and composite one on
top the other and retain this multiple resolution facility? The only
compositing method I see for NSImage is the carious drawInRect/
drawAtPoint/drawRepresentation (and the deprecated composite variants)
that all require a specified size). So as near as I can figure it, to
properly composite two NSImages, you would have to do something like:
scan through all the representations of each image and union all the
sizes
scan through all those sizes and composite the two NSImages at that
size
create a union NSImage.
Possible, but fairly ugly, and not entirely trivial. Is this the only
way.
Yes, I think you're right. I tried to to use NSImage's compositing
facility to init two NSImage's from two IconRef's and then composite
one on the other. If I examine the NSImage's after initializing they
have all the different representations of the original IconRef: 16x16,
32x32, 128x128, 256x256 etc. The underlying representation is given as
private NSIconRefImageRep's. Here is the code:
CGSize iconSize = [self iconSize];
NSRect iconRect = NSMakeRect(0, 0, iconSize.width, iconSize.height);
NSImage * resultImage = [[NSImage alloc]
initWithIconRef:targetIconRef];
NSImage * overlayImage = [[NSImage alloc]
initWithIconRef:overlayIconRef];
[resultImage lockFocus];
[overlayImage drawInRect:iconRect fromRect:iconRect
operation:NSCompositeSourceOver fraction:1.0];
[resultImage unlockFocus];
But examining the contents of the resultImage shows that the
underlying representation has now been changed to a single
NSCGImageSnapshotRep at 128x128 with all other image representation
data being lost. And is there a way to convert this back to an IconRef
object if that's the object that's needed?
Best,
Dalmazio
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden