Objective c 掩蔽时CGAffineTransformMakeRotation错误

Objective c 掩蔽时CGAffineTransformMakeRotation错误,objective-c,iphone,ipad,ios9,cgaffinetransform,Objective C,Iphone,Ipad,Ios9,Cgaffinetransform,我在屏蔽旋转图像时有一个错误。该漏洞在iOS 8上不存在(即使它是用iOS 9 SDK构建的),在非视网膜iOS 9 iPad(iPad2)上也不存在。我没有更多仍然在iOS 8上的retina iPad,同时,我还更新了构建,以支持32位和64位架构。关键是,我不能确定iOS9的更新是否带来了bug,或者两种架构设置的改变 这个bug的本质是这样的。我迭代了一系列的图像,旋转它们的角度由我想从图片中取出的片段数决定,并在每次旋转时屏蔽图片以获得图片的不同部分。除了源图像旋转M_-PI、2*M_

我在屏蔽旋转图像时有一个错误。该漏洞在iOS 8上不存在(即使它是用iOS 9 SDK构建的),在非视网膜iOS 9 iPad(iPad2)上也不存在。我没有更多仍然在iOS 8上的retina iPad,同时,我还更新了构建,以支持32位和64位架构。关键是,我不能确定iOS9的更新是否带来了bug,或者两种架构设置的改变

这个bug的本质是这样的。我迭代了一系列的图像,旋转它们的角度由我想从图片中取出的片段数决定,并在每次旋转时屏蔽图片以获得图片的不同部分。除了源图像旋转M_-PI、2*M_-PI、3*M_-PI或4*M_-PI倍(或倍数,即5*M_-PI、6*M_-PI等)外,其他一切都正常工作。当它旋转1-3*M_PI倍时,产生的图像被错误地遮罩-应该是透明的部分最终变成黑色。当它旋转4*M_PI倍时,结果图像的遮罩以nil图像结束,从而在最后一步(我将结果图像添加到数组中)中使应用程序崩溃

我使用CIImage进行旋转,CGImage掩蔽用于性能原因(这种组合显示了最佳性能),因此如果可能的话,我更愿意保留这种方法选择

更新:下面显示的代码在后台线程上运行

以下是代码片段:

CIContext *context = [CIContext contextWithOptions:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:kCIContextUseSoftwareRenderer]];

    for (int i=0;i<[src count];i++){
        //for every image in the source array


        CIImage * newImage = [[CIImage alloc] init];

        if  (IS_RETINA){
            newImage = [CIImage imageWithCGImage:[[src objectAtIndex:i] CGImage]];
        }else {
            CIImage *tImage = [CIImage imageWithCGImage:[[src objectAtIndex:i] CGImage]];
            newImage = [tImage imageByApplyingTransform:CGAffineTransformMakeScale(0.5, 0.5)];
        }


        float angle = angleOff*M_PI/180.0;
        //angleOff is just the inital angle offset, If I want to start cutting from a different start point


        for (int j = 0; j < nSegments; j++){
            //for the given number of circle slices (segments)


            CIImage * ciResult = [newImage imageByApplyingTransform:CGAffineTransformMakeRotation(angle + ((2*M_PI/ (2 * nSegments)) + (2*M_PI/nSegments) * (j)))];
            //the way the angle is calculated is specific for the application of the image later. In any case, the bug happens when the resulting angle is M_PI, 2*M_PI, 3*M_PI and 4*M_PI


            CGPoint center = CGPointMake([ciResult extent].origin.x + [ciResult extent].size.width/2, [ciResult extent].origin.y+[ciResult extent].size.width/2);

            for (int k = 0; k<[src count]; k++){
            //this iteration is also specific, it has to do with how much of the     image is being masked in each iteration, but the bug happens irrelevant to this iteration


                CGSize dim = [[masks objectAtIndex:k] size];

                if (IS_RETINA && (floor(NSFoundationVersionNumber)>(NSFoundationVersionNumber_iOS_7_1))) {

                    dim = CGSizeMake(dim.width*2, dim.height*2);

                }//this correction was needed after iOS 7 was introduced, not sure why :)

                CGRect newSize = CGRectMake(center.x-dim.width*1/2,center.y+((circRadius + orbitWidth*(k+1))*scale-dim.height)*1, dim.width*1, dim.height*1);
                //the calculation of the new size is specific to the application, I don't find it relevant.


                CGImageRef imageRef = [context createCGImage:ciResult fromRect:newSize];

                CGImageRef maskRef = [[masks objectAtIndex:k] CGImage];

                CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                                     CGImageGetHeight(maskRef),
                                                     CGImageGetBitsPerComponent(maskRef),
                                                     CGImageGetBitsPerPixel(maskRef),
                                                     CGImageGetBytesPerRow(maskRef),
                                                     CGImageGetDataProvider(maskRef),
                                                     NULL,
                                                     YES);

                CGImageRef masked = CGImageCreateWithMask(imageRef, mask);
                UIImage * result = [UIImage imageWithCGImage:masked];

                CGImageRelease(imageRef);
                CGImageRelease(masked);
                CGImageRelease(maska);
                [temps addObject:result];
            }

        }
    }
CIContext*context=[CIContext contextWithOptions:[NSDictionary Dictionary WithObject:[NSNumber numberWithBool:NO]forKey:KCIContextSeSoftwareRenderer];
对于(int i=0;i