opencv IplImage 到带有 ARC 泄漏的 UIImage
我正在使用此函数将 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];
不知何故,该内存永远不会被释放。 如何解决这个问题?
I'm converting a stream of IplImages to UIImage using this function:
+(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;
}
However, I get a memory warning after a few images and then a crash . Running in instruments revelas that the problematic line is where memory is allocated is:
NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];
Somehow this memory is never released.
How can this be fixed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论