开发者

Zooming in on CIImage or 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 even开发者_如何学Ctually save an NSImage.

How would I go about zooming in on either of these objects?


“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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜