NSImageView 中的图像放大缩小
谁能给我推荐一个在 NSImageView 中缩放图像的好示例代码。 谢谢。
Can anyone please suggest me a good sample code for zooming image in NSImageView.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您查看文档,您会发现 NSImageView 不支持此功能。 请改用 Image Kit。
If you look at the documentation, you'll see that NSImageView doesn't support this. Use Image Kit instead.
虽然从技术上来说 NSImageView 并不支持这一点,但这是可能的。 我相信通过更改您正在使用的 NSView 的边界,并确保图像设置为“按比例向下”或“按比例向上或向下”。
这段代码似乎对我有用,在 OSX 10.9 (Mavericks) 上,
我也成功地将图像视图“嵌入”滚动视图内,然后在滚动视图上使用放大功能。 青年MMV
While technically NSImageView doesn't technically support this, it is possible. I believe by changing the bounds of the NSView that you're using, and make sure that the image is set to "Proportionally Down", or "Proportionally Up or Down".
This code seems to work for me, on OSX 10.9 (Mavericks)
I have also had success "embedding" an image view inside a scroll view, and then using magnification on the scroll view. YMMV
也许您想尝试使用 ImageKit 的 IKImageView 代替。 这为您提供了缩放、旋转等功能……所有这些都是免费的。
Perhaps you want to try using ImageKit's IKImageView instead. This gives you zooming, rotation, etc...all for free.
您可以将图像视图嵌入到
NSScrollView
中。 像这样准备你的滚动视图:并将其 documentView 设置为你的图像视图:
You can embed your image view in an
NSScrollView
. Prepare your scroll view like this:and set its documentView to your image view:
除非我误解了你所说的“缩放图像”的意思 - 这似乎很简单。 获取视图的框架并随意缩放(尽管添加限制显然是非常明智的),同时将图像缩放类型设置为 NSImageScaleProportionallyUpOrDown :
Unless I misunderstand what you mean by "zooming image" - this seems to be pretty easy. Take the view's frame and scale it at will (although adding limits is obviously highly advisable), while having the image scaling type set to
NSImageScaleProportionallyUpOrDown
: