CIImageMBS scale to width/height

It’s way over my head but how do you take a CIImageMBS and scale/stretch it to the dimensions that you want in width/height? I’m sure it has something to do with CIFilterAffineTransformMBS and NSAffineTransformMBS, but no idea how to do it.

Var xTransform As New CIFilterAffineTransformMBS
Var xTransformScale as New NSAffineTransformMBS
xTransform.inputImage = xCF
xTransformScale.scale ???
xTransform.inputTransform = xTransformScale
xCF = xTransform.outputImage

Here you go:

Dim pic As Picture = LogoMBS(500)
Dim image As CIImageMBS = CIImageMBS.imageWithPicture(pic)

Dim filter As New CIFilterLanczosScaleTransformMBS

Const targetWidth = 600.0
Const targetHeight = 400.0

Dim scale As Double = targetHeight / image.Extent.Height
Dim aspect As Double = targetWidth / (image.Extent.Width * scale)

filter.inputImage = image
filter.inputScale = scale
filter.inputAspectRatio = aspect

Dim result As Picture = filter.outputImage.RenderPicture

Backdrop = result

And I’ll add a scaleTo function to do this for your convenience.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.