-(NSImage *)roateSourceImage:(NSImage *) sourceImage ByDegrees:(CGFloat)degrees
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSRect imageBounds = {NSZeroPoint, [sourceImage size]};
NSBezierPath* boundsPath = [NSBezierPath
bezierPathWithRect:imageBounds];
NSAffineTransform* transform = [NSAffineTransform transform];
[transform rotateByDegrees:degrees];
[boundsPath transformUsingAffineTransform:transform];
NSRect rotatedBounds = {NSZeroPoint, [boundsPath bounds].size};
NSImage* rotatedImage = [[NSImage alloc]
initWithSize:rotatedBounds.size];
// center the image within the rotated bounds
imageBounds.origin.x = NSMidX(rotatedBounds) - (NSWidth
(imageBounds) / 2);
imageBounds.origin.y = NSMidY(rotatedBounds) - (NSHeight
[Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转]
本文介绍了如何在Objective-C的Cocoa环境中,通过NSAffineTransform来实现NSImage图像的旋转操作。详细展示了`roateSourceImage:ByDegrees:`方法的实现过程,包括创建贝塞尔路径、设置旋转变换、创建新的旋转图像并绘制原图像。
摘要由CSDN通过智能技术生成