Re: Cursor - Unable to use retina image
Re: Cursor - Unable to use retina image
- Subject: Re: Cursor - Unable to use retina image
- From: "David M. Cotter" <email@hidden>
- Date: Thu, 20 Nov 2014 22:22:30 -0800
see fixed code below
> On Oct 1, 2013, at 10:22 AM, Abdul Sowayan <email@hidden> wrote:
>
> Hi folks,
>
> I have two images, a retina and a non-retina image that I would like to use as a Cursor. I crop the transparency out of the images and combine them into one NSImage that has two representations, a retina and a non-retina one. I then use the combined image to set NSCursor’s image. However, this doesn’t end up displaying a retina Cursor. I’m not sure why that is the case.
>
> My sample code can be downloaded from:
> https://www.dropbox.com/s/k9lj5pjsn253d43/Cursor.zip
>
> Any help would be greatly appreciated.
>
> Thanks,
> Abdul
NSCursor* GetCursorUsingNSImage(NSImage* imageNormal, NSImage* imageRetina, float hotSpotX, float hotSpotY)
{
@autoreleasepool
{
NSData* lowData = [imageNormal TIFFRepresentation];
NSBitmapImageRep* lowRep = [NSBitmapImageRep imageRepWithData:lowData];
NSData* hiData = [imageRetina TIFFRepresentation];
NSBitmapImageRep* hiRep = [NSBitmapImageRep imageRepWithData:hiData];
// this is the secret sauce:
[hiRep setSize: [imageNormal size]];
NSPoint hotSpotPt;
{
NSRect rectLow = [imageNormal cursorImageRectWithHotSpotX:hotSpotX hotSpotY:hotSpotY];
hotSpotX = hotSpotX - rectLow.origin.x;
hotSpotY = NSMaxY(rectLow) - hotSpotY;
hotSpotPt = NSMakePoint(hotSpotX, hotSpotY);
}
NSImage* finalImage = [[NSImage alloc] initWithSize:[imageNormal size]];
// the order you add them does NOT matter
[finalImage addRepresentation:lowRep];
[finalImage addRepresentation:hiRep];
NSCursor* cursor = [[NSCursor alloc] initWithImage:finalImage hotSpot: hotSpotPt];
return cursor;
}
}
_______________________________________________
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