4
capture
은 CGWindowListCreateImage()
으로 호출하여 반환 된 CGImageRef
입니다. initWithCGImage:size:
을 통해 NSImage
으로 직접 변환하려고하면 크기가 신비하게 두 배가됩니다. 대신 수동으로 NSBitmapImageRep
을 capture
에서 만든 다음 비어있는 NSImage
에 추가하면 모든 것이 정상적으로 작동합니다.CGImageRef에서 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
이 예상되는 동작인가?
망막 이미지가있는 것 같습니다 – Andy
같은 문제가 있습니까? –