The problem is that with high resolution images, NSImage's size will
return the size in points (72/inch), which is where I'm guessing you
get "newSize" from. Since you draw the image in that lower resolution
value, and then draw that expanded, you get pixelization.

So, for example (to make the numbers easy), if it is 720dpi 1" x 1"
image (i.e. 720px x 720px), [tempImage size] will return (72,72) - you
make a new image at that size, draw the 720px image into that 72px
size, and then scale the 72px size up.

Instead of making a new image, you could start by just using the
"tempImage" and draw that (and if you need to make changes to it,
you'll need to iterate through the NSImageRep's inside NSImage to find
the highest resolution one and base your tempImage's size based on that)

// Get the CGImageRef from the image....
NSBitmapImageRep *rep = (NSBitmapImageRep *)[yourImage
bestRepresentationForDevice: nil]; // is there a better way to get the
nsbitmapimagerep out of an nsimage?
CGImageRef cgImage = [rep CGImage];

I'm not sure what the purpose of the code with the comment 'just sets
the dimensions of newSize properly' is.

The 'tempImage' had all the data from the original file. When you
called lockFocus and drew into the new image, that data was thrown
away - all that was left was a bitmap at screen resolution with size
newSize. -lockFocus should be considered a somewhat expensive thing
to do. It's making a new bitmap memory buffer, drawing, and setting
up a context for you to draw into. Sometimes this is genuinely what
you need, but if not, it's churn. It also trashes CG-level caches.

As Glenn suggested, it looks like you probably wanted to draw directly
with the 'templmage' here. The draw methods take a destination rect,
and the image will be scaled to fill it with whatever quality is
available. A caveat: if your image is drawn at _multiple_ resolutions
to the screen, you need to advise NSImage not to optimize itself to
the first context it's drawn into and throw away extra data. This is
done by calling [image setDataRetained:YES]. Then the image may still
create an optimized cache when it is drawn, but all the original data
will be around if it's drawn to a context that doesn't match the
original destination. If the image is infrequently drawn, for example
if it's _only_ redrawn once per different resolution at which it's
rendered, you may want to ask it not to create the cache as well,
which is done with [image setCacheMode:NSImageCacheNever].