今天我真的需要你的帮助!我正在调试另一个开发人员创建的一个旧的objective-c应用程序,有一个只在iOS 11上出现的新错误。这个错误来自尝试创建“临时视图”时使用的图像处理函数,类似于这个-> 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中不再起作用了吗?
感谢您的帮助!
发布于 2019-01-17 13:27:36
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 = ...
...https://stackoverflow.com/questions/49084800
复制相似问题