2014-12-10 2 views
4

captureCGWindowListCreateImage()으로 호출하여 반환 된 CGImageRef입니다. initWithCGImage:size:을 통해 NSImage으로 직접 변환하려고하면 크기가 신비하게 두 배가됩니다. 대신 수동으로 NSBitmapImageRepcapture에서 만든 다음 비어있는 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 

이 예상되는 동작인가?

+0

망막 이미지가있는 것 같습니다 – Andy

+0

같은 문제가 있습니까? –

답변

1

documentationinitWithCGImage:size:에 대한 상태 :

당신은이 CGImage 그리기에 해당 도면이 이외의 이미지에 대해 아무것도, 가정해서는 안된다.

결국 나는 NSBitmapImageRep 인스턴스로 직접 작업을 계속했습니다.

관련 문제