最近工程里捕捉到創(chuàng)建二維碼時偶爾會閃退幔虏,最后發(fā)現(xiàn)跟EAGLContext相關(guān),問題已經(jīng)處理了,清空EAGLContext碘梢,重新設(shè)置EAGLContext,有遇到相關(guān)問題的網(wǎng)友可評論伐蒂,我回頭貼上處理方案的代碼
關(guān)鍵地方是[EAGLContext setCurrentContext:nil];
- (UIImage*)resizeCodeImage:(CIImage*)imagewithSize:(CGSize)size {
? ? EAGLContext *curContext = [EAGLContext currentContext];
? ? if(curContext) {
? ? ? ? [EAGLContext setCurrentContext:nil];
? ? }
? ? CGRect extent = CGRectIntegral(image.extent);
? ? CGFloatscaleWidth = size.width/CGRectGetWidth(extent);
? ? CGFloatscaleHeight = size.height/CGRectGetHeight(extent);
? ? size_twidth =CGRectGetWidth(extent) * scaleWidth;
? ? size_theight =CGRectGetHeight(extent) * scaleHeight;
? ? CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceGray();
? ? CGContextRef contentRef = CGBitmapContextCreate(nil, width, height, 8, 0, colorSpaceRef, (CGBitmapInfo)kCGImageAlphaNone);
? ? CGColorSpaceRelease(colorSpaceRef);
? ? CIContext *context = [CIContext contextWithOptions:nil];
? ? CGImageRefimageRef = [contextcreateCGImage:imagefromRect:extent];
? ? CGContextSetInterpolationQuality(contentRef, kCGInterpolationNone);
? ? CGContextScaleCTM(contentRef, scaleWidth, scaleHeight);
? ? CGContextDrawImage(contentRef, extent, imageRef);
? ? CGImageRefimageRefResized =CGBitmapContextCreateImage(contentRef);
? ? CGContextRelease(contentRef);
? ? CGImageRelease(imageRef);
? ? UIImage*img = [UIImageimageWithCGImage:imageRefResized];
? ? if(curContext) {
? ? ? ? [EAGLContext setCurrentContext:curContext];
? ? }
? ? CGImageRelease(imageRefResized);
? ? returnimg;
}