我正在使用此功能将IplImages流转换为UIImage:
+(UIImage *)createUIImageFromIplImage:(IplImage *)image
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
CGImageRef imageRef = CGImageCreate(image->width, image->height,
image->depth, image->depth * image->nChannels, image->widthStep,
colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault,
provider, NULL, false, kCGRenderingIntentDefault);
UIImage* ret = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);
return ret;
}
然而,在几张图像然后崩溃后,我收到内存警告。在乐器中运行意味着有问题的行是分配内存的地方:
NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];
不知何故,这个记忆永远不会被释放。 如何解决这个问题?