Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code and Decode a CGContextRef




Le 28 nov. 07 à 17:57, Jason Barker a écrit :

Actually, I knew that it was a reference and not a "container". I've just
not done much with C-style functions and structs, and so Quartz makes my
head swim a bit, trying to change from Objective-C style syntax to C-style
syntax.


Anyway, I just wasn't sure if I had to code/decode each property from the
CGContextRef (width, height, bitsPerComponent, bytesPerRow, dataSize,
colorspace, data, etc.) or if there was an Objective-C type that could just
do it all for me.


With regards to the function CGImageDestinationCreateWithData(), I think I
understand what to pass in for the last three parameters it takes (namely
'type', 'count' and 'options') but I don't know how to go from a CGImageRef
to a CFMutableDataRef. Is this what I'm supposed to do? And then once I have
a CGImageDestinationRef, how do I code/decode that?


Thanks for your help,
Jason


The CFMutableDataRef is the destination buffer where it will store your image data.
NSMutableData *imgData = [NSMutableData data];
CGImageDestinationRef dest = CGImageDestinationCreateWithData (imgData, ...);
CGImageDestinationAddImage(dest, myCGImageRef, NULL);
CGImageDestinationFinalize(dest);
CFRelease(dest);


Now, imgData should contains your image data and you can encode it.

Your image can contains a lots of properties (width, height, resolution, colorspace, etc...) so you don't have to archive additional meta-data.

To restore the context, you probably can use CGImageSource to create a CGImageRef, creating your context as needed, and then draw the image on your new context.


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Code and Decode a CGContextRef (From: "Jason Barker" <email@hidden>)
 >Re: Code and Decode a CGContextRef (From: David Duncan <email@hidden>)
 >Re: Code and Decode a CGContextRef (From: "Jason Barker" <email@hidden>)
 >Re: Code and Decode a CGContextRef (From: Alastair Houghton <email@hidden>)
 >Re: Code and Decode a CGContextRef (From: "Jason Barker" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.