• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Image scaling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Image scaling


  • Subject: Image scaling
  • From: Adam Knight <email@hidden>
  • Date: Fri, 4 Jan 2008 16:25:53 -0600

I think I'm missing something here.

I need to take an image and scale it (very cleanly) down while keeping the metadata. The source is a JPEG file on-disk (typically from a digital camera). The destination is an NSData object in memory that is JPEG-encoded with the same metadata.

I tried this using CIImage and a CILanczosScaleTransform filter then using NSBitmapImageRep's initWithCIImage method. This worked very well and made a great image, but it looks like Apple's initWithCIImage code leaks a whole copy of the image outside of my reach. I'm working with too many images for this to be good. Also, this method drops the file metadata entirely (EXIF, etc.) and doesn't appear to give me the chance to add it back in.

So then I tried using a CGImageRef with CGImageSourceCreateThumbnailAtIndex and copying the metadata with CGImageSourceCopyPropertiesAtIndex. This works well except that the scaled image is blurry and not at all professional. I tried fiddling with CGContextSetInterpolationQuality to no avail. Almost there.

It appears that NSImage does not scale the backing image, but only the display one. Tricks involving drawing onto a new context are not thread-safe. Thus, I cannot use that.


The only solution that's coming to mind is one I really dread:

* Get the JPEG data with a CGImageSourceRef
* Store the metadata
* Make a CIImage (from the original file or the CGImage)
* Do the transform that works
* Make the CIImage a CGImage without using NSBitmapImageRep (Can I even do this? I haven't found this path.)
* Copy the metadata to a CGImageDestinationRef item along with the CGImage
* Generate the JPEG data object using CGImageDestinationCreateWithData


This seems overly complicated just to scale an image properly. Everything appears highly optimized for drawing on-screen rather than to a data structure in a threaded app.

Can anyone tell me how I can easily scale an image with a good/ excellent quality in a thread-safe manner in Mac OS X?


Adam Knight Co-Founder; CTO Barton Springs Software

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Image scaling
      • From: "Shawn Erickson" <email@hidden>
    • Re: Image scaling
      • From: Scott Ribe <email@hidden>
    • Re: Image scaling
      • From: Chris Williams <email@hidden>
    • Re: Image scaling
      • From: Adam Knight <email@hidden>
  • Prev by Date: Re: iChat-Theater not working from Cocoa apps
  • Next by Date: Re: Printing a layer-backed view
  • Previous by thread: Streaming a file as it gets recorded?
  • Next by thread: Re: Image scaling
  • Index(es):
    • Date
    • Thread