【发布时间】:2014-12-10 13:11:04
【问题描述】:
capture 是从对CGWindowListCreateImage() 的调用返回的CGImageRef。当我尝试直接通过initWithCGImage:size: 将它变成NSImage 时,它的大小神秘地翻了一番。如果我改为从capture 手动创建一个NSBitmapImageRep,然后将其添加到一个空的NSImage 中,一切正常。
我的硬件设置是视网膜 MBP + 非视网膜外接显示器。捕捉是在非视网膜屏幕上进行的。
NSLog(@"capture image size: %d %d", CGImageGetWidth(capture), CGImageGetHeight(capture));
NSLog(@"logical image size: %f %f", viewRect.size.width, viewRect.size.height);
NSBitmapImageRep *debugRep;
NSImage *image;
//
// Create NSImage directly
image = [[NSImage alloc] initWithCGImage:capture size:NSSizeFromCGSize(viewRect.size)];
debugRep = [[image representations] objectAtIndex:0];
NSLog(@"pixel size, NSImage direct: %d %d", debugRep.pixelsWide, debugRep.pixelsHigh);
//
// Create representation manually
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:capture];
image = [[NSImage alloc] initWithSize:NSSizeFromCGSize(viewRect.size)];
[image addRepresentation:imageRep];
[imageRep release];
debugRep = [[image representations] objectAtIndex:0];
NSLog(@"pixel size, NSImage + manual representation: %d %d", debugRep.pixelsWide, debugRep.pixelsHigh);
日志输出:
capture image size: 356 262
logical image size: 356.000000 262.000000
pixel size, NSImage direct: 712 524
pixel size, NSImage + manual representation: 356 262
这是预期的行为吗?
【问题讨论】:
-
你好像有视网膜图像
-
遇到同样的问题,有什么更新吗?
标签: objective-c cocoa nsimage cgimageref