• 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: CGImage to NSImage, or PDFPage?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGImage to NSImage, or PDFPage?


  • Subject: Re: CGImage to NSImage, or PDFPage?
  • From: Brian Postow <email@hidden>
  • Date: Tue, 10 Aug 2010 18:49:22 -0400

On Aug 10, 2010, at 6:02 PM, Nick Zitzmann wrote:

>
> On Aug 10, 2010, at 3:45 PM, Brian Postow wrote:
>
>> Is there something obvious that I'm missing?
>
> Yes. If you can require Leopard or later, then just create an NSBitmapImageRep using -initWithCGImage:, then create the NSImage with the size of the CGImage and add that NSBitmapImageRep to the NSImage. If not, then create a new image with the size of the CGImage, lock focus on the image, draw the CGImage using CGContextDrawImage(), and unlock focus.
>
> Nick Zitzmann
> <http://www.chronosnet.com/>
>
>


Excellent! Now is there an easier way to get the CGImage out of the PDFPage than:

	PDFPage * pg = [doc pageAtIndex: pageNum -1];

	NSData* imgData = [pg dataRepresentation];
	NSImage* img = [[NSImage alloc] initWithData:imgData ];

	imgData = [img TIFFRepresentation];

	CGImageSourceRef imageSource =
		CGImageSourceCreateWithData((CFDataRef)imgData,  NULL);
	NSDictionary * options = [NSDictionary dictionaryWithObject:
											(id)kCFBooleanTrue
										forKey: (id) kCGImageSourceShouldCache];
	CGImageRef imgRef = CGImageSourceCreateImageAtIndex(imageSource, 0, options);


? About 1/2 of the time I seem to be crashing in the dataRepresentation call for some reason...


Brian Postow
Senior Software Engineer
Acordex Imaging Systems

_______________________________________________

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: CGImage to NSImage, or PDFPage?
      • From: Brian Postow <email@hidden>
References: 
 >CGImage to NSImage, or PDFPage? (From: Brian Postow <email@hidden>)
 >Re: CGImage to NSImage, or PDFPage? (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: CGImage to NSImage, or PDFPage?
  • Next by Date: NSTextView in NSCollectionView doesn't draw
  • Previous by thread: Re: CGImage to NSImage, or PDFPage?
  • Next by thread: Re: CGImage to NSImage, or PDFPage?
  • Index(es):
    • Date
    • Thread