NS图像旋转
我有一个窗口,其中包含 NSView 的子类。 在视图中,我放置了一个 NSImage。
我希望能够将图像旋转 90 度,将图像的(新)左上角保持在视图的左上角。 当然,我必须旋转图像,然后平移它以将原点放回原位。
在Carbon中,我发现CGContextRotateCTM可以满足我的需求。 但是,我在 ObjC 中找不到正确的调用。 setFrameCenterRotation 似乎没有做任何事情,并且在 setFrameRotation 中,我似乎无法弄清楚原点在哪里,所以我可以适当地翻译。
似乎在动。 当我调整窗口大小时,它会放置图像(或其一部分,我似乎也有一个奇怪的剪切问题),当我滚动时,它会跳转到不同的(并不总是相同的)位置。
这对任何人都有意义吗?
谢谢
I have a window with an subclass of NSView in it. Inside the view, I put an NSImage.
I want to be able to rotate the image by 90 degrees, keeping the (new) upper left corner of the image in the upper left corner of the view. Of course, I will have to rotate the image, and then translate it to put the origin back into place.
In Carbon, I found CGContextRotateCTM which does what I want . However, I can't find the right call in ObjC. setFrameCenterRotation doesn't seem to do anything, and in setFrameRotation, I can't seem to figure out where the origin is, so I can approprately translate.
It seems to move. When I resize the window it puts the image (or part of it, I seem to have a strange clipping issue as wel) and when I scroll, it jumps to a different (and not always the saem) location.
Does this make sense to anyone?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在屏幕上旋转我正在使用的应用程序的文本,而 Cocoa (我假设您在问题中指的是 Cocoa 而不是 ObjC)这样做的方法是使用 NSAffineTransform。
下面是一个可以帮助您入门的片段
旋转的数学运算在这里可能会有点棘手,因为上面所做的是旋转您正在绘制的坐标系。 我的90度旋转是逆时针旋转。
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
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.