NS图像坐标

发布于 2024-09-26 21:46:42 字数 843 浏览 5 评论 0原文

嘿伙计们, 我有一个大图像,然后我通过以下方式提取图像的一部分:

[mBaseImage lockFocus];
NSBitmapImageRep* bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(startX,startY,width,height)];
[mBaseImage unlockFocus];

后跟:

extractedImage = [[NSImage alloc] initWithSize:[bitmapImageRep size]];
[extractedImage addRepresentation:bitmapImageRep];

其中 extractedImage 是 NSImage *。

后来,当我尝试使用 NSDrawNinePartImage 绘制提取的图像时,我意识到虽然我按照 http://www.karlkraft.com/index.php/2007/11/14/nsdrawninepartimage/ 我意识到,当我指定 0,0 时,它显示图像的左上角,这意味着 0,0 是左上角,而不是像链接中的示例中的左下角。我尝试设置 setFlipped 但它似乎只是翻转图像。有谁知道如何将坐标返回到左下角 0,0 的位置吗?

哦,我忘了提及,我使用图像作为按钮,因此它呈现为 NSButton。

问候, 汉族

hey guys,
I have a large image, and then i'm extracting a portion of the image out via:

[mBaseImage lockFocus];
NSBitmapImageRep* bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(startX,startY,width,height)];
[mBaseImage unlockFocus];

followed by:

extractedImage = [[NSImage alloc] initWithSize:[bitmapImageRep size]];
[extractedImage addRepresentation:bitmapImageRep];

where extractedImage is NSImage *.

Later on while i'm trying to draw the extractedImage using NSDrawNinePartImage, I realised that while I was specifying the 9 parts following the example at http://www.karlkraft.com/index.php/2007/11/14/nsdrawninepartimage/
I realised that when i specified 0,0 it shows the upper left handcorner of the image, which means that 0,0 is the upper left hand corner instead of the lower left hand corner like in the example in the link. I tried setting the setFlipped however it seems to be only flipping the image. does anyone have any idea how I can get the coordinates back to where 0,0 is at the bottom left?

Oh and I forgot to mention that i'm using the image as a button, so it's presented as a NSButton.

Regards,
Han

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初熏 2024-10-03 21:46:42

好吧,我找到了。这是代码中某个地方的一个流氓 [image setFlip:...] 导致了所有的混淆。

Ok i found it. It was a rogue [image setFlip:...] somewhere in the code that was causing all the mixup..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文