NSImage rotation

怎甘沉沦 提交于 2019-12-06 16:40:18

I rotate text on the screen for an app I work on and the Cocoa (I assume you mean Cocoa and not ObjC in your question) way of doing this is to use NSAffineTransform.

Here's a snippet that should get you started

double rotateDeg = 90;
NSAffineTransform *rotate = [[NSAffineTransform alloc] init];
NSGraphicsContext *context = [NSGraphicsContext currentContext];

[context saveGraphicsState];
[rotate rotateByDegrees:rotateDeg];
[rotate concat];

    /* Your drawing code [NSImage drawAtPoint....]for the image goes here 
       Also, if you need to lock focus when drawing, do it here.       */

[rotate release];
[context restoreGraphicsState];

The mathematics on the rotation can get a little tricky here because what the above does is to rotate the coordinate system that you are drawing into. My rotation of 90 degrees is a counter-clockwise rotation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!