Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a mutable array of CGImageRefs?

I want to keep a mutable collection of CGImageRefs. Do I need to wrap them in NSValue, and if so how do I wrap and unwrap them properly? Can I get away with using a C array? If so how do I construct it and how do I add elements to it later? Is it significantly more costly to use UIImages instead of CGImageRefs as the elements of the collection?

like image 342
RexOnRoids Avatar asked Nov 28 '22 23:11

RexOnRoids


2 Answers

You can directly add CGImage to NSMutableArray. You will need to cast to (id) to avoid compiler warnings.

CFType is bridged to NSObject. You can send any message NSObject responds to to any CFType. In particular, -retain and -release work as normal.

like image 85
Ken Avatar answered Dec 09 '22 15:12

Ken


2011: just in case someone's still looking You can wrap CGImageRef in NSValues by using

+ (NSValue *)valueWithBytes:(const void *)value objCType:(const char *)type

hence:

CGImageRef cgImage = [self cgImageMethod];
NSValue *cgImageValue = [NSValue valueWithBytes:&cgImage objCType:@encode(CGImageRef)];
[array addObject:cgImageValue];

to retrieve:

CGImageRef retrievedCGImageRef;
[[array objectAtIndex:0] getValue:&retrievedCGImageRef ];

hope this helps somebody

like image 44
cate Avatar answered Dec 09 '22 14:12

cate