Ios 图像编辑过程中的内存增长
我正在尝试获取PDF页面的图像并对其进行编辑。一切都很好,但内存却有了巨大的增长。探查器说没有任何内存泄漏。此外,分析器还指出,90%的内存分配在UIGraphicsGetCurrentContext()和UIGraphicsGetImageFromCurrentImageContext()上。此代码不在循环中运行,不需要用@autorelease将其包装Ios 图像编辑过程中的内存增长,ios,objective-c,memory-management,core-graphics,leptonica,Ios,Objective C,Memory Management,Core Graphics,Leptonica,我正在尝试获取PDF页面的图像并对其进行编辑。一切都很好,但内存却有了巨大的增长。探查器说没有任何内存泄漏。此外,分析器还指出,90%的内存分配在UIGraphicsGetCurrentContext()和UIGraphicsGetImageFromCurrentImageContext()上。此代码不在循环中运行,不需要用@autorelease将其包装 if ((pageRotation == 0) || (pageRotation == 180) ||(pageRotati
if ((pageRotation == 0) || (pageRotation == 180) ||(pageRotation == -180)) {
UIGraphicsBeginImageContextWithOptions(cropBox.size, NO, PAGE_QUALITY);
}
else {
UIGraphicsBeginImageContextWithOptions(
CGSizeMake(cropBox.size.height, cropBox.size.width), NO, PAGE_QUALITY);
}
CGContextRef imageContext = UIGraphicsGetCurrentContext();
[PDFPageRenderer renderPage:_PDFPageRef inContext:imageContext pagePoint:CGPointMake(0, 0)];
UIImage *pageImage = UIGraphicsGetImageFromCurrentImageContext();
[[NSNotificationCenter defaultCenter] postNotificationName:@"PAGE_IMAGE_FETCHED" object:pageImage];
UIGraphicsEndImageContext();
但是调试显示,只有在我开始编辑获取的图像时,内存才会增长。对于图像编辑,我使用Leptonica库。例如:
+(void) testAction:(UIImage *) image{
PIX * pix =[self getPixFromUIImage:image];
pixConvertTo8(pix, FALSE);
pixDestroy(&pix);
}
在pixConvertTo8之前,应用程序需要13MB,在-50MB之后。显然,增长取决于图像大小。转换方法:
+(PIX *) getPixFromUIImage:(UIImage *) image{
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage));
UInt8 const* pData = (UInt8*)CFDataGetBytePtr(data);
Pix *myPix = (Pix *) malloc(sizeof(Pix));
CGImageRef myCGImage = [image CGImage];
myPix->w = CGImageGetWidth (myCGImage)-1;
myPix->h = CGImageGetHeight (myCGImage);
myPix->d = CGImageGetBitsPerPixel([image CGImage]) ;
myPix->wpl = CGImageGetBytesPerRow (myCGImage)/4 ;
myPix->data = (l_uint32 *)pData;
myPix->colormap = NULL;
myPix->text="text";
CFRelease(data);
return myPix;
}
另外,对不起,我的英语很糟糕