이 내 이미지 크기 조정 코드 :IKImageBrowserView는 내가 할 수있는 것보다 훨씬 빨리 이미지 크기를 조정할 수 있습니까?
CALayer *newCALayer = [[CALayer layer] retain];
NSImage* image = [[NSImage alloc] initWithData:[NSData dataWithContentsOfFile:path]];
CGImageRef newCGImageFullResolution = [image CGImageForProposedRect:nil context:nil hints:nil];
CGContextRef context = CGBitmapContextCreate(NULL, drawRect.size.width, drawRect.size.height,
CGImageGetBitsPerComponent(newCGImageFullResolution),
CGImageGetBytesPerRow(newCGImageFullResolution),
CGImageGetColorSpace(newCGImageFullResolution),
CGImageGetAlphaInfo(newCGImageFullResolution));
CGContextDrawImage(context, CGRectMake(0, 0, drawRect.size.width, drawRect.size.height), newCGImageFullResolution);
CGImageRef scaledImage = CGBitmapContextCreateImage(context);
newCALayer.contents = (id)scaledImage;
CGImageRelease(scaledImage);
newCALayer.contentsGravity = kCAGravityResizeAspect;
newCALayer.opacity = 0.0;
newCALayer.anchorPoint = CGPointMake(0.0f,0.0f);
newCALayer.frame = CGRectMake(0.0,
0.0,
[Singleton sharedSingleton].fullscreenRect.size.width,
[Singleton sharedSingleton].fullscreenRect.size.height);
[newCALayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
//CGImageRelease(cgImageFullResolution); (bonus points if you can explain why I can't release this! I mean, I can release the scaled image ok??)
CGContextRelease(context);
[image release];
아니, 난 내 GUI가 물어 느낌 때문에 사진을 미리로드하기 위해 백그라운드 스레드에서이 모든 일을하고있다. CALayers가보기에 끝나기 위해 동기화를 얻는 작업과 설정하지 않은 작업이 필요했습니다.
그러나 나는 이것이 얼마나 빠른지를 설명하는 용어가 "개"라고 생각합니다.
IKImageView와 비교하면 스크롤 할 수있는 것보다 빠르게 이미지 축소판이 튀어 오릅니다.
아무도 내가 지금하고있는 것보다 더 잘 처리하는 방법에 대한 제안 사항이 있습니까?
다른 말로하면, 제 문제는 초고속 UX를 갖고 싶다는 것입니다. 이것을 달성하는 방법은 CALayers에 프리로드하는 것입니다 (이것이 잘못된 것일 수 있습니까? NSImageView와 IK-stuff를 시도했지만 적어도 CALayer는 그보다 낫습니다).
/처음 독자 - SO 규칙, 내 말은, 당신은 Google의 순위를 변경 ... omg! :) 여기
OS X 10.5 호환성이 필요하거나 10.6 만 지원합니까? (이미 게시 한 코드에는 10.6이 필요하지만 명확히하는 데 도움이됩니다.) – NSGod
10.6 만 유효합니다. app-store의 일종의 히트는 호환성에 "재설정"되었습니까? :) – Torkel