【问题标题】:Issues with NSImage add representation in Retina DisplayNSImage 的问题在 Retina Display 中添加表示
【发布时间】:2012-10-01 22:17:07
【问题描述】:

我有两个 CGImageRef,imgRef1 和 imgRef2。 我想用这些 CGImageRefs 的两种表示创建一个 NSImage(用于创建 NSCursor)。为此,我使用了 BitMapRepresentation initWithCGImage 方法,然后将这些表示添加到 NSImage。但这不起作用。

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

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

【问题讨论】:

    标签: macos nsimage retina-display


    【解决方案1】:

    您需要颠倒顺序。我的测试表明,高分辨率图像需要位于 TIFF 的索引 0 处,而较低分辨率的图像需要位于索引 1 处。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      相关资源
      最近更新 更多