-(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图片进行旋转]
最新推荐文章于 2022-09-30 09:08:16 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)