• 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
Re: Cocoa won't draw CMYK jpeg
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa won't draw CMYK jpeg


  • Subject: Re: Cocoa won't draw CMYK jpeg
  • From: Robert Clair <email@hidden>
  • Date: Thu, 13 Sep 2007 09:18:44 -0400



Simpler?!? :-) Ok... it is a shame that there's not an (Apple provided) NSCGImageImageRep... yet.


NSURL *urlToFile = [NSURL fileURLWithPath:[sheet filename]];
CGImageSourceRef mySource = CGImageSourceCreateWithURL((CFURLRef) urlToFile)
CGImageRef myImage = CGImageSourceCreateImageAtIndex(mySource, 0, NULL);
CFRelease(mySource);


And then...

CGContextRef *cgContext = (CGContextRef) [[NSGraphicsContext currentContext] currentPort];
CGContextDrawImage(cgContext, destinationRect, myImage);

Well, I agree it is simple to read in an image and draw it this way. What is *not* simple is cramming this into a large app that uses NSImage in various places to draw, archive, get at its pixels, etc. What I really want is an NSBitmapImageRep.


The obvious way doesn't work:

* create a CGImage from a CGImageSource

* extract the CGColorSpace and other relevant info from the CGImage and use it to create a CGBitmapContext

* draw the CGImage into the CGBitmapContext

* stuff the pixels from the CGBitmapContext into an NSBitmapImageRep

* set the profile property for the NSBitmapImageRep... except... CURSES ! FOILED AGAIN ! There is apparently no way to get the profile out of CGColorSpaceRef.


Glenn's suggestion of subclassing NSImageRep is interesting and I may try it. But I'm also going to see if this hack works:


* create an image source from the file with CGImageSourceCreateWithURL()

* use CGImageDestinationCreateWithData(...) to set up and image destination that outputs tiff to CFMutableData

* use CGImageDestinationAddImageFromSource(...) to put the image into the data

* cast the resulting CFMutableDataRef to NSData* and use [NSBitmapImageRep initWithData:].

Have to test and make sure nothing gets lost in the journey. Hackery, but localized hackery that can be contained in a single routine for replacement if something better comes along.

Bob


_______________________________________________


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: Cocoa won't draw CMYK jpeg
      • From: Scott Thompson <email@hidden>
References: 
 >Cocoa won't draw CMYK jpeg (From: Robert Clair <email@hidden>)
 >Re: Cocoa won't draw CMYK jpeg (From: Scott Thompson <email@hidden>)
 >Re: Cocoa won't draw CMYK jpeg (From: Robert Clair <email@hidden>)
 >Re: Cocoa won't draw CMYK jpeg (From: Scott Thompson <email@hidden>)

  • Prev by Date: Re: Incremental Development?
  • Next by Date: Re: Cocoa won't draw CMYK jpeg
  • Previous by thread: Re: Cocoa won't draw CMYK jpeg
  • Next by thread: Re: Cocoa won't draw CMYK jpeg
  • Index(es):
    • Date
    • Thread