UIImage を使用して NSImage の drawInRect:fromRect:operation:fraction の動作をエミュレートする必要があり、誰かが既にこれを行っており、コードを共有する意思があるかどうか、または (より良い) 最善のアプローチは何か疑問に思っています。
CGImageCreateWithImageInRect (最後のコードを参照) を使用してこれを実行しようとしましたが、期待した結果が得られません。コードは実際にMacでこれをテストしていることに注意してください(現時点ではiPhoneですべてを実行することはできません)ので、NSImageからCGImageを取得する際に問題が発生する可能性があります
- (void)drawInRect:(CGRect)rect fromRect:(CGRect)fromRect alpha:(float)alpha {
CGContextRef context;
CGImageRef originalImageRef;
CGImageRef subimageRef;
#if ERMac
context=[[NSGraphicsContext currentContext] graphicsPort];
CGImageSourceRef source;
source = CGImageSourceCreateWithData((CFDataRef)[self TIFFRepresentation], NULL);
originalImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
CFRelease(source);
#else
context=UIGraphicsGetCurrentContext();
originalImageRef=CGImageRetain([self CGImage]);
#endif
subimageRef = CGImageCreateWithImageInRect (originalImageRef, fromRect);
CGContextDrawImage(context, rect, subimageRef);
if (subimageRef)
CGImageRelease(subimageRef);
if (originalImageRef)
CGImageRelease(originalImageRef);
}