NSImageView 中的图像放大缩小

发布于 2024-07-25 19:02:18 字数 46 浏览 3 评论 0原文

谁能给我推荐一个在 NSImageView 中缩放图像的好示例代码。 谢谢。

Can anyone please suggest me a good sample code for zooming image in NSImageView.
Thanks.

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

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

发布评论

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

评论(5

落花随流水 2024-08-01 19:02:18

如果您查看文档,您会发现 NSImageView 不支持此功能。 请改用 Image Kit

If you look at the documentation, you'll see that NSImageView doesn't support this. Use Image Kit instead.

仙女 2024-08-01 19:02:18

虽然从技术上来说 NSImageView 并不支持这一点,但这是可能的。 我相信通过更改您正在使用的 NSView 的边界,并确保图像设置为“按比例向下”或“按比例向上或向下”。

这段代码似乎对我有用,在 OSX 10.9 (Mavericks) 上,

   NSSize size = [_imageView bounds].size;

   NSSize newSize = NSMakeSize(size.width * 0.90, size.height * 0.90);

   [_imageView setBoundsSize: newSize];

我也成功地将图像视图“嵌入”滚动视图内,然后在滚动视图上使用放大功能。 青年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)

   NSSize size = [_imageView bounds].size;

   NSSize newSize = NSMakeSize(size.width * 0.90, size.height * 0.90);

   [_imageView setBoundsSize: newSize];

I have also had success "embedding" an image view inside a scroll view, and then using magnification on the scroll view. YMMV

原谅过去的我 2024-08-01 19:02:18

也许您想尝试使用 ImageKit 的 IKImageView 代替。 这为您提供了缩放、旋转等功能……所有这些都是免费的。

Perhaps you want to try using ImageKit's IKImageView instead. This gives you zooming, rotation, etc...all for free.

荒路情人 2024-08-01 19:02:18

您可以将图像视图嵌入到 NSScrollView 中。 像这样准备你的滚动视图:

private var scrollView: NSScrollView = {
    let view = NSScrollView()
    view.allowsMagnification = true
    view.minMagnification = 1
    view.maxMagnification = 5
    return view
}()

并将其 documentView 设置为你的图像视图:

scrollView.documentView = myImageView

You can embed your image view in an NSScrollView. Prepare your scroll view like this:

private var scrollView: NSScrollView = {
    let view = NSScrollView()
    view.allowsMagnification = true
    view.minMagnification = 1
    view.maxMagnification = 5
    return view
}()

and set its documentView to your image view:

scrollView.documentView = myImageView
情未る 2024-08-01 19:02:18

除非我误解了你所说的“缩放图像”的意思 - 这似乎很简单。 获取视图的框架并随意缩放(尽管添加限制显然是非常明智的),同时将图像缩放类型设置为 NSImageScaleProportionallyUpOrDown :

NSRect newFrame = NSMakeRect(newOriginX, newOriginY, newSizeWidth, newSizeHeight);
[myNSImageView setFrame:newFrame];

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:

NSRect newFrame = NSMakeRect(newOriginX, newOriginY, newSizeWidth, newSizeHeight);
[myNSImageView setFrame:newFrame];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文