[Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转]

本文介绍了如何在Objective-C的Cocoa环境中,通过NSAffineTransform来实现NSImage图像的旋转操作。详细展示了`roateSourceImage:ByDegrees:`方法的实现过程,包括创建贝塞尔路径、设置旋转变换、创建新的旋转图像并绘制原图像。
摘要由CSDN通过智能技术生成
-(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
                       
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值