Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在CGContextDrawImage中收到内存警告导致应用程序崩溃?_Iphone_Ios_Memory Leaks_Cgcontextdrawimage - Fatal编程技术网

Iphone 在CGContextDrawImage中收到内存警告导致应用程序崩溃?

Iphone 在CGContextDrawImage中收到内存警告导致应用程序崩溃?,iphone,ios,memory-leaks,cgcontextdrawimage,Iphone,Ios,Memory Leaks,Cgcontextdrawimage,我的应用程序因收到内存警告而崩溃。当我使用仪器运行应用程序时,我遇到以下内存泄漏问题。 这是我关于这个方法的完整代码 - (UIImage *)resizeImage:(UIImage *)orignalImage newWidth:(int)width newHeight:(int)height bgColor:(UIColor *)bgColor { CGRect newRect; if((orignalImage.size.width>width) || (origna

我的应用程序因收到内存警告而崩溃。当我使用仪器运行应用程序时,我遇到以下内存泄漏问题。

这是我关于这个方法的完整代码

  - (UIImage *)resizeImage:(UIImage *)orignalImage newWidth:(int)width newHeight:(int)height bgColor:(UIColor *)bgColor
    {
CGRect newRect;
if((orignalImage.size.width>width) || (orignalImage.size.height>height))
{
    float newWidth,newHeight;
    if(orignalImage.size.width>orignalImage.size.height)
    {
        newWidth=width;
        newHeight=(height*orignalImage.size.height)/orignalImage.size.width;
    }
    else if(orignalImage.size.height>orignalImage.size.width)
    {
        newWidth=(width*orignalImage.size.width)/orignalImage.size.height;
        newHeight=height;
    }
    else
    {
        newWidth=width;
        newHeight=height;
    }
    newRect.origin.x=(width-newWidth)/2;
    newRect.origin.y=(height-newHeight)/2;
    newRect.size.width=newWidth;
    newRect.size.height=newHeight;
}
else
{
    newRect.origin.x=(width-(orignalImage.size.width))/2;
    newRect.origin.y=(height-(orignalImage.size.height))/2;
    newRect.size.width=orignalImage.size.width;
    newRect.size.height=orignalImage.size.height;
}

CGImageRef imageRef = [orignalImage CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);

//if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;

CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), 4 * width, CGImageGetColorSpace(imageRef), alphaInfo);
CGContextSetFillColorWithColor(bitmap, bgColor.CGColor);
CGContextFillRect(bitmap, CGRectMake(0, 0, width, height));
CGContextDrawImage(bitmap, newRect, imageRef);
CGImageRef newImgRef = CGBitmapContextCreateImage(bitmap);
UIImage *newImg = [UIImage imageWithCGImage:newImgRef];

CGContextRelease(bitmap);
CGImageRelease(newImgRef);
return newImg;
}

有人可以告诉我我的代码中有什么错误。任何帮助都会得到感谢。

您没有发布
imageRef
,这是您的漏洞。不过不知道崩溃的原因。啊,让我检查一下thanksafter release imageRef是否仍在同一行显示内存泄漏。您可以启用此文件,并检查是否仍显示内存警告。您解决了此问题吗?我最近也遇到同样的问题,你能给我一些建议吗?非常感谢