gpt4 book ai didi

objective-c - 在 cocoa 中水平切片 NSImage

转载 作者:行者123 更新时间:2023-12-03 17:36:03 25 4
gpt4 key购买 nike

我需要将 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];

}

关于objective-c - 在 cocoa 中水平切片 NSImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7040993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com