我今天真的需要你的帮助!我正在调试由另一个开发人员创建的旧的objective-c应用程序,而且这个新错误只出现在iOS 11上。
该错误来自于在尝试创建" Scratch View"时使用的图像处理功能,类似于此 - > https://github.com/joehour/ScratchCard
但是,自从iOS 11以来,该功能不再起作用,在上面的代码中我在[Unknown process name] CGImageMaskCreate: invalid image provider: NULL.
上发生错误< - 变量CGDataProviderRef没有创建dataProvider(null)
// Method to change the view which will be scratched
- (void)setHideView:(UIView *)hideView
{
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
UIGraphicsBeginImageContextWithOptions(hideView.bounds.size, NO, 0);
[hideView.layer renderInContext:UIGraphicsGetCurrentContext()];
hideView.layer.contentsScale = scale;
_hideImage = UIGraphicsGetImageFromCurrentImageContext().CGImage;
UIGraphicsEndImageContext();
size_t imageWidth = CGImageGetWidth(_hideImage);
size_t imageHeight = CGImageGetHeight(_hideImage);
CFMutableDataRef pixels = CFDataCreateMutable(NULL, imageWidth * imageHeight);
_contextMask = CGBitmapContextCreate(CFDataGetMutableBytePtr(pixels), imageWidth, imageHeight , 8, imageWidth, colorspace, kCGImageAlphaNone);
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(pixels);
CFRelease(pixels);
CGContextSetFillColorWithColor(_contextMask, [UIColor blackColor].CGColor);
CGContextFillRect(_contextMask, self.frame);
CGContextSetStrokeColorWithColor(_contextMask, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(_contextMask, _sizeBrush);
CGContextSetLineCap(_contextMask, kCGLineCapRound);
CGImageRef mask = CGImageMaskCreate(imageWidth, imageHeight, 8, 8, imageWidth, dataProvider, nil, NO);
_scratchImage = CGImageCreateWithMask(_hideImage, mask);
CGDataProviderRelease(dataProvider);
CGImageRelease(mask);
CGColorSpaceRelease(colorspace);
}
我不是这个图像处理功能的专家,我真的因为调试这个部分而迷失了...... 有谁知道为什么这个功能在iOS 11中不再起作用了?
感谢您的帮助!
答案 0 :(得分:1)
iOS 11停止处理CGDataProviderCreateWithCFData(null)
,因此您需要设置pixels
的长度。
类似的东西:
...
CFMutableDataRef pixels = CFDataCreateMutable(NULL, imageWidth * imageHeight);
CFDataSetLength(pixels, imageWidth * imageHeight); // this is the line you're missing for iOS11+
_contextMask = ...
...