Mac OS X 용 앱을 개발 중입니다. NSImage
크기를 200x300과 같은 특정 크기로 조정하려고합니다. 비 망막 Mac에서는 잘 작동합니다. 그러나 Retina Mac의 경우 400x600 크기로 이미지의 크기가 조정됩니다. 이는 예상했던대로 두 배입니다. 내 프로젝트는 응용 프로그램이 실행중인 장치가 망막 또는 비 망막인지 여부에 관계없이 주어진 크기에 따라 이미지의 크기를 조정해야합니다. 어떻게 목표를 달성 할 수 있습니까?망막 장치에서 이미지 크기 조정
스케일 속성을 측정하려고했습니다. 망막의 크기가 2.0이므로 필요한 이미지의 절반 만 이미지의 크기를 조정합니다.
그러나 모니터에 연결하면 하나는 망막이고 다른 하나는 망막이 아니며 동일한 문제가 다시 발생합니다. 사전에
-(void)resizeImage:(NSImage *)sourceImage newSize:(CGSize)newSize
{
NSString *newImagePath = [[[Utility documentPath] stringByAppendingPathComponent:imagefolder] stringByAppendingPathComponent:@"imageName"];
[sourceImage setScalesWhenResized:YES];
[sourceImage setSize:newSize];
NSImage *newImage = [[NSImage alloc] initWithSize:newSize];
[newImage lockFocus];
NSRect frame = NSMakeRect(0, 0, newSize.width, newSize.height);
[NSGraphicsContext saveGraphicsState];
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame xRadius:0 yRadius:0];
[path addClip];
[sourceImage drawInRect:frame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
[newImage unlockFocus];
CGImageRef CGImage = [newImage CGImageForProposedRect:nil context:nil hints:nil];
NSBitmapImageRep *imgRep = [[[NSBitmapImageRep alloc] initWithCGImage:CGImage] autorelease];
NSData *data = [imgRep representationUsingType:NSPNGFileType properties: nil];
[[NSFileManager defaultManager] createFileAtPath:newImagePath contents:data attributes:nil];
[newImage release];
}
감사 : 여기
내가 크기 조정에 사용한 코드입니다.
그리고 무엇이 문제입니까? 이미지 크기를 조정할 때 스케일을 고려하는 것이 좋습니다. – trojanfoe
난 우리가 응용 프로그램을 실행하는 장치 (망막 또는 비 망막)에 상관없이 주어진 크기에 따라 이미지의 크기를 조정하고자했습니다. – iPhoneDv
같은 크기의 포인트를 의미합니까? – paulmelnikow