NSImage help

Discussion in 'Mac Programming' started by italiano40, Dec 18, 2008.

  1. italiano40 macrumors 65816

    italiano40

    Joined:
    Oct 7, 2007
    Location:
    NY
    #1
    I am using the NSImage class to hold an image
    should i use NSImage class to scale it to another resolution
    or is their another class that i can use to scale an image
     
  2. BravoBug macrumors newbie

    Joined:
    Dec 8, 2008
    Location:
    Oregon, USA
    #2
    you can use NSImage's setSize method, but there are lots of 'gotchas' when you're working with NSImage, NSImageRep, etc. NSImage, for instance, interprets the size as rendered at 72dpi. Meaning, if you load an NSImage from a 400dpi JPEG, and ask it -size, it will return a 72dpi size.

    You may want to dive into the actual ImageRep. Ask NSImage for its -representations, and grab one that suits you. Or better yet, just store your image in NSBitmapImageRep from the get-go.

    As far as scaling goes, you can play around with various methods, such as setSize, as mentioned, or drawing it into a new image using -lockFocus. For bitmap imagereps, you can also create an NSGraphicContext from the NSBitmapImageRep, set it, and redraw the original image (drawInRect) to scale. (Then -restoreGraphicsContext)

    Lots of options, just gotta figure out what will work best for your situation. Be sure to check out all the ImageRep and NSImage related Apple docs.
     

Share This Page