Issues with NSImage add representation in Retina Display

故事扮演 提交于 2019-12-08 02:04:21

问题


I have two CGImageRef, imgRef1 and imgRef2. I want to create a NSImage with two representations of those CGImageRefs (for creating NSCursor). For this I used BitMapRepresentation initWithCGImage method and then added those representations to NSImage. But this doesn't work.

Then I tried creating NSImage from imageRef1 and imgRef2 and then generated NSData from those NSImage's using TiffRepresentation and then added those representations to finally get the NSImage. But again this is giving low res Image in retina displays. HEre is the sample code: (Any help would be appreciated)

float aHotSpotX = (float)nHotSpotX; float aHotSpotY = (float)nHotSpotY;

NSSize nsSz;
nsSz.width = CGImageGetWidth(nLowImageRef);
nsSz.height = CGImageGetHeight(nLowImageRef);

NSImage* image = [[NSImage alloc] initWithSize:nsSz];

// Could have directly used NSBitmapImage initWithCGImage but some issues with that. Will revisit
NSImage *lImage = CreateNSImageFromCGImage(nLowImageRef);
NSData *lowData = [lImage TIFFRepresentation];

NSBitmapImageRep *lowRep = [NSBitmapImageRep imageRepWithData:lowData];
[image addRepresentation:lowRep];


NSImage  *hImage = CreateNSImageFromCGImage(nHiImageRef);
NSData *hiData = [hImage    TIFFRepresentation];

NSBitmapImageRep *hiRep = [NSBitmapImageRep imageRepWithData:hiData];
[image addRepresentation:hiRep];


NSCursor*   aCursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(aHotSpotX, aHotSpotY)];

[image release];

回答1:


You need to reverse the order. My tests have shown that the higher res image needs to be at index 0 of the TIFF and the lower res image at index 1.



来源:https://stackoverflow.com/questions/12681902/issues-with-nsimage-add-representation-in-retina-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!