iphone: creating image without allocating new memory


iphone: creating image without allocating new memory



the pointer data if pointing to some image generated by an iphone application. Does anybody now if using CGBitmapContextCreate make a copy of this data or does it use the image "in place"?

Ideally, I'd like to reuse the information in data* and not create any additional copy of this image.

void* data = <my data>;  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef imageContext = CGBitmapContextCreate(data, w, h, 8, w*8, colorSpace, kCGBitmapByteOrder32Big|kCGImageAlphaPremultipliedLast); CGImageRef imageRef = CGBitmapContextCreateImage(imageContext); UIImage* image =[[UIImage alloc] initWithCGImage:imageRef]; 

More generally, this method of creating image seems rather convoluted to me. Does anybody knows what's going on here? Is there any easier way to create UIImage?

Thanks


How do you duplicate a file in XCode?

1:

Unit testing an iPhone static library with XCode 3
From here it looks like CGBitmapContextCreate will just use the memory you passed in. Image getting pixelated when used as part of an animation in iPhone animationBut the data may be copied by the call to CGBitmapContextCreateImage, . UITableView Animation Headache Apple docs:. iPhone OpenGL ES incorrect alpha blending
Discussion The CGImage object returned by CGBitmapContextCreateImage is created by a copy operation. Does a NSURLConnection retain its delegate?Subsequent changes to the bitmap graphics context did not affect the contents of the returned image. Which button was tapped… iPhone and Obj-C questionIn any cases the copy operation actually follows copy-on-write semantics, so this the actual physical copy of the bits occur only if the underlying data in the bitmap graphics context is modified. ConnectionAs a consequence, you may want to use the resulting image and release it before you perform additional drawing into the bitmap graphics context. In this way, you must avoid the actual physical copy of the data..

2:

What around any thing like this:.
void * data = <my data>; NSData * newData = [NSData dataWithBytesNoCopy:data length:lengthOfData]; UIImage * image = [[UIImage alloc] initWithData:newData]; 


50 out of 100 based on 15 user ratings 340 reviews