• 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: Trying to get a TIFF from a CGImageRef isn't working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to get a TIFF from a CGImageRef isn't working


  • Subject: Re: Trying to get a TIFF from a CGImageRef isn't working
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 15 Jan 2014 14:56:03 -0800

On Wed, Jan 15, 2014, at 02:14 PM, Steve Mills wrote:
> I've been wrestling with this all day and nothing is working. This code:
>
> NSImage*              nsImage = [[NSImage alloc] initWithCGImage:cgImage
> size:NSZeroSize];
> NSBitmapImageRep*     biRep = [[NSBitmapImageRep alloc]
> initWithCGImage:cgImage];
> NSData*               nsImageData = [biRep
> TIFFRepresentationUsingCompression:NSTIFFCompressionPackBits factor:0];
>
> Produces this error on the call to TIFFRepresentationUsingCompression:
>
> CGImageDestinationFinalize failed for output type 'public.tiff'
>
> I've also tried NSTIFFCompressionNone and NSTIFFCompressionLZW for the
> compression type.

What is the data format of the original CGImageRef? ImageIO might not be
able to write it to TIFF. (It might have too many bits per pixel, or the
values might be in the wrong order, etc.)

>
> Hmm, after working some more, I was able to get it to work be forcing the
> image rep to copy the pixels rather than simply glomming onto the
> CGImageRef:
>
> NSImage*               nsImage = [[NSImage alloc] initWithCGImage:cgImage
> size:NSMakeSize(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage))];
> NSBitmapImageRep*      bitmapImageRep;
>
> [nsImage lockFocus];
> bitmapImageRep = [[NSBitmapImageRep alloc]
> initWithFocusedViewRect:NSMakeRect(0, 0, nsImage.size.width,
> nsImage.size.height)];
> [nsImage unlockFocus];

I'm surprised this works. As mentioned in the 10.6 AppKit release notes
[1], -[NSImage lockFocus] does not cause +[NSView focusView] to return a
view anymore, so -initWithFocusedViewRect: should be a no-op.

The release notes discuss how to convert image data of arbitrary formats
into something you can work with. [2]

--Kyle Sluder

[1] "NSImage, CGImage, and CoreGraphics impedance matching",
<https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/>

[2] "NSBitmapImageRep: CoreGraphics impedance matching and performance
notes",
<https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/>
_______________________________________________

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: Trying to get a TIFF from a CGImageRef isn't working
      • From: Steve Mills <email@hidden>
References: 
 >Trying to get a TIFF from a CGImageRef isn't working (From: Steve Mills <email@hidden>)

  • Prev by Date: Trying to get a TIFF from a CGImageRef isn't working
  • Next by Date: Re: Trying to get a TIFF from a CGImageRef isn't working
  • Previous by thread: Trying to get a TIFF from a CGImageRef isn't working
  • Next by thread: Re: Trying to get a TIFF from a CGImageRef isn't working
  • Index(es):
    • Date
    • Thread