放大 CIImage 还是 NSImage?
我正在 Cocoa 应用程序中的网络摄像头拍照,我想放大收到的图像的中心。我首先接收一个 CIImage
并最终保存一个 NSImage
。
我将如何放大这些对象中的任何一个?
I am taking photos from a webcam in my Cocoa application and I would like to zoom in on the centre of the image I receive. I start by receiving a CIImage
and eventually save an NSImage
.
How would I go about zooming in on either of these objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“缩放”有几个意思。您至少需要裁剪图像,并且可能想要放大。或者您可能希望保留缩放仅用于显示。
CGImage
要裁剪它,请使用 CICrop 滤镜。
要缩放它,请使用 CILanczosScaleTransform 过滤器或 CIAffineTransform 过滤器。
要裁剪和缩放它,请使用两个滤镜。只需将裁剪的输出作为比例的输入即可。
NSImage
Crop 和缩放在这里是相同的操作。您需要创建一个具有所需大小的新的空 NSImage(无论是源裁剪的大小,如果您不缩放,还是增加的大小,如果您要缩放),将焦点锁定在它上面,从将源图像放入目标图像的边界矩形中,并解锁焦点。
如果目标矩形与源(裁剪)矩形的大小不同,它将缩放;如果它们大小相同,它将简单地逐像素复制或合成。
“Zoom” means a couple of things. You'll need at least to crop the image, and you may want to scale up. Or you may want to reserve scaling for display only.
CGImage
To crop it, use a CICrop filter.
To scale it, use either a CILanczosScaleTransform filter or a CIAffineTransform filter.
To crop and scale it, use both filters. Simply pass the output of the crop as the input of the scale.
NSImage
Crop and scale are the same operation here. You'll need to create a new, empty NSImage of the desired size (whether it's the size of the source crop if you won't zoom or an increased size if you will zoom), lock focus on it, draw the crop rectangle from the source image into the bounding rectangle of the destination image, and unlock focus.
If the destination rectangle is not the same size as the source (crop) rectangle, it will scale; if they are the same size, it will simply copy or composite pixel-to-pixel.