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如果這個答案對您有幫助,請點擊勾號將其標記爲已接受 –