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

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

概述-(NSImage *)roateSourceImage:(NSImage *) sourceImage ByDegrees:(CGFloat)degrees{ NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSRect imageBounds = {NSZeroPoint, [sourceImage size]}
-(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                                                    (imageBounds) / 2);        // set up the rotation transform    transform = [NSAffinetransform transform];    [transform translateXBy:+(NSWIDth(rotatedBounds) / 2) yBy:+     (NSHeight(rotatedBounds) / 2)];    [transform rotateBydegrees:degrees];    [transform translateXBy:-(NSWIDth(rotatedBounds) / 2) yBy:-     (NSHeight(rotatedBounds) / 2)];        // draw the original image,rotated,into the new image    [rotatedImage lockFocus];       [transform set] ;    [sourceImage drawInRect:imageBounds fromrect:NSZeroRect operation:NSCompositecopy fraction:1.0];    [rotatedImage unlockFocus] ;    [pool drain];        return rotatedImage ;}
总结

以上是内存溢出为你收集整理的[Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转]全部内容,希望文章能够帮你解决[Cocoa]_[初级]_[使用NSAffineTransfrom 对NSImage图片进行旋转]所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1052333.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存