IPhone. Get a pointer to the data behind the CGDataProvider?

I am trying to take a CGImage and copy its data into a buffer for later processing. The code below is what I have so far, but one thing I don't like is it copies the image data twice. Once for CGDataProviderCopyData()

and once for the call :getBytes:length

to imgData. I haven't been able to find a way to copy the image data directly to my clipboard and cut the step CGDataProviderCopyData()

, but there must be a way ... any pointers? (... pun ftw)

NSData * imgData = (NSData *) (CGDataProviderCopyData (CGImageGetDataProvider (myCGImageRef)));

CGImageRelease (myCGImageRef);

// i've got a previously-defined pointer to an available buffer called "mybuff"
[imgData getBytes: mybuff length: [imgData length]];
+2


a source to share


2 answers


See this answer: Does CGDataProviderCopyData () actually copy bytes? Or just a pointer?



It looks like direct access to the buffer behind the CGDataProvider is limited to private APIs.

0


a source


If you don't see a performance issue when you use the tools to measure it, I don't think copying it twice is a huge problem. You can always store CFDataRef imgData directly instead of mybuff.

Edit
I'm talking about this kind of code:
In your class interface, add an array:

NSMutableArray *images;

      

In your init :: method, create an array:

images = [[NSMutableArray alloc] init];

      



and has a dealloc;

-(void)dealloc{
    [images release];
}

      

and in your code that saves each image:

CGDataRef imageDataRef = CGDataProviderCopyData(CGImageGetDataProvider(myCGImageRef)));
[images addObject: (NSData*)imageDataRef];
CGRelease(imageDataRef);

      

0


a source







All Articles