NSImage问题在Retina Display中添加表示形式 [英] Issues with NSImage add representation in Retina Display

查看:176
本文介绍了NSImage问题在Retina Display中添加表示形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个CGImageRef,imgRef1和imgRef2. 我想创建一个具有两个CGImageRefs的两种表示形式的NSImage(用于创建NSCursor).为此,我使用了BitMapRepresentation initWithCGImage方法,然后将这些表示添加到NSImage中.但这是行不通的.

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.

然后我尝试从imageRef1和imgRef2创建NSImage,然后使用TiffRepresentation从这些NSImage生成NSData,然后添加这些表示以最终获得NSImage.但这又使视网膜显示器的图像分辨率降低. 这里是示例代码:(任何帮助将不胜感激)

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;

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];

推荐答案

您需要颠倒顺序.我的测试表明,分辨率较高的图像必须位于TIFF的索引0处,分辨率较低的图像必须位于TIFF的索引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.

这篇关于NSImage问题在Retina Display中添加表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆