Scale quality of Canvas control

In OSX I use ‘Image Events’ with an AppleScript to resize and save images
Example ScalePicture

[quote=74564:@Axel Schneider]In OSX I use ‘Image Events’ with an AppleScript to resize and save images
Example ScalePicture [/quote]

Tempscript is missing. The project does not launch :frowning:

Don’t know if this was intended, but I just duplicated one of the scripts and rename it ti Tempscript. Then it runs. Careful not to open too big pictures; the window will be resized beyond the screen’s vertical borders.

Oh boy! – renamed it to “tempscript”. Who scrambled the letters on my keyboard?

Sorry, had forgotten it, have corrected it (tempscript is important)

Example ScalePicture

[quote=74584:@Axel Schneider]Sorry, had forgotten it, have corrected it (tempscript is important)

Example ScalePicture[/quote]

a simpler example

Rescale Picture OSX[/quote]

a simpler example

Rescale Picture OSX

[quote=67210:@Sam Rowlands]The awesome thing is, you don’t need to do anything special on the Mac to get this, Xojo already uses Core Graphics, there is a declare for adjusting the quality of the scaling. However simple using Xojo function in a Mac app and you already get the power of CoreGraphics.

If you want to draw icons, I would recommend using NSImage however, either via the Retina Kit or via the MBS plugin or MacOSLib, as the system will then choose the most appropriate icns resource to draw for you.[/quote]

I am sorry for digging this out but I am using the CIFilter “CILanczosScaleTransform” for scaling down and have awesome
results. Is there any other easy way to do this ? I mean some declare for the Xojo picture/CGImage you just throw over.

[quote=177374:@Rob Egal]I am sorry for digging this out but I am using the CIFilter “CILanczosScaleTransform” for scaling down and have awesome
results. Is there any other easy way to do this ? I mean some declare for the Xojo picture/CGImage you just throw over.[/quote]
CILanczosScaleTransform generally does a good job, there are situations where other techniques are better.

There are a couple of things to watch:

  • On Yosemite, the memory management of CGImage to CIImage under 32-Bit is not as good as it was on Mavericks (can easily leak).
  • For best performance, you should use a CIContext to render the image onto screen, however you should use a CIImageAccumulator also.
  • Core Image’s stability with 32-Bit apps on Yosemite, simply isn’t as good as it was. I’m hoping that with 64-Bit it will be better.
  • When resizing interface used graphics (not large images), it can actually be faster to use Quartz 2D instead of Core Image.

Interesting (again), thanks, Sam!
Do you have any hints on where to get some tips on the Accumulator use? The docs don’t tell me that much what’s it good for and where and how it should be used.

Sure;

  • Create a CIImageAccumulator with “imageAccumulatorWithExtent:format:” to the size and format that you need.
  • Use setImage: to specify the data.
  • Use the image property to obtain the image.

CIImageAccumulator will flatten the CIImage, effectively caching the image so the entire filter chain doesn’t need to be reevaluated every single time.

Thanks, Sam!

You’re welcome

Here is a comparison of the methods (OSX)
ScaleTest

@Axel: will have a look at the example. From your TV Plaketten I don’t see a big difference. Or my eyes are too old. Recently, I had some pictures to scale, where the Xojo algorithm didn’t do very well. With Photoshop’s bicubic scale and a bit sharpening there was a very noticeable difference.

I made a test image, the differences are now easier to see. (included in the ScaleTest)

Can you also include the time taken to get the image on screen (scaling and drawing time). This way people can choose between speed v.s. quality.

added Time ScaleTest

I looked at the code and fixed a couple of minor issues, also improved the accuracy of the method testing by using microseconds instead of ticks.

http://www.ohanaware.com/xojo/ScaleTest.zip

I’m getting twice faster times than Xojo DrawPicture using CGContextDrawImage, even with high interpolation quality.

[code]methodTimer = microseconds
try
Const kCGInterpolationHigh = 3
Declare Sub CGContextSetInterpolationQuality Lib “Cocoa” ( context As Ptr, quality As Integer )
declare sub CGContextDrawImage lib “Cocoa” (cntxt As Ptr, r As CGRect, img As Ptr)
declare sub CFRelease lib “Cocoa” (id as ptr)

Dim destPic as new picture( targetSize.width, targetSize.height )
dim destCntxt As Ptr = Ptr( destPic.Graphics.Handle(Graphics.HandleTypeCGContextRef) )
dim srcImg As Ptr = mypic.CopyOSHandle(Picture.HandleType.MacCGImage)

dim r As CGRect
r.w = targetSize.width
r.h = targetSize.height

CGContextSetInterpolationQuality(destCntxt, kCGInterpolationHigh)
CGContextDrawImage(destCntxt, r, srcImg)

CFRelease(srcImg)

cnv6.backdrop = destPic

end try
lblTicks6.text = format( microseconds-methodTimer, “###,###,###,###,###,###” ) + " ms"[/code]