0
我需要将NSImage水平切分为两半。请帮助我。提前致谢。在可可中水平切片NSImage
我需要将NSImage水平切分为两半。请帮助我。提前致谢。在可可中水平切片NSImage
这是我刚添加到我的工具箱中的一个技巧。我已经将它添加为NSImage上的一个类别。您传入源图像和从中切出新图像的矩形。下面的代码:
+ (NSImage *) sliceImage:(NSImage *)image fromRect:(NSRect)srcRect {
NSRect targetRect = NSMakeRect(0, 0, srcRect.size.width, srcRect.size.height);
NSImage *result = [[NSImage alloc] initWithSize:targetRect.size];
[result lockFocus];
[image drawInRect:targetRect fromRect:srcRect operation:NSCompositeCopy fraction:1.0];
[result unlockFocus];
return [result autorelease];
}
非常感谢。谢谢。 – Soorya
@Soorya如果这个答案对您有帮助,请点击勾号将其标记为已接受 –