Hi,
I wrote a method for load Image into CALayer. This is the code:
- (CGImageRef)loadImage:(NSString*)path {
// Get data image
CGImageRef image = NULL;
NSData *data = [NSData dataWithContentsOfFile:path];
CFDataRef imgData = (CFDataRef)data;
CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData (imgData);
// Get CGImage from CFDataRef
image = CGImageCreateWithJPEGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
// If the image isn't a JPG Image, would be PNG file
if (!image)
image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
return image;
}
I use this method in my CALayer:
NSString *pathString = // my image path;
aLayer = [CALayer layer];
aLayer.contents = [self loadImage:pathString];
It's work. I finalize my view (using garbage collector) but my application has leaks. Should I release CFDataRef imgData? I read that garbage collector does not work in Core Foundation.
Thanks and excuse my english.