Nearest Neighbor image scaling with Quartz 2D

Discussion in 'iOS Programming' started by KnightWRX, Mar 12, 2012.

  1. macrumors Pentium


    Jan 28, 2009
    Quebec, Canada
    Is there a way to select the scaling algorithm used by Apple's CGContextScaleCTM() function ? Basically, I see they are doing some kind of filtering, probably a simple bilinear filter, but I want no filtering or interpolation at all, I want a very basic nearest neighbor algorithm.

    Thankfully, my pixels are stored as a linear array, so I was able to write my own scaling function with a very simple algorithm, but I was wondering if there was a "cleaner" way that would let me implement all sorts of filtering in my scaling function in case I ever wanted cleaner graphics.

    I can't find squat in the documentation aside from CGContextScaleCTM to scale a Bitmap context and that function doesn't take a filtering argument. Doing it manually means I would have to write a bunch of scalers for 4 byte pixel arrays and call the appropriate one based on the filtering argument sent to the function.

Share This Page