【问题标题】:Issue on image data processing with iOS 11iOS 11 处理图像数据的问题
【发布时间】:2019-01-17 13:27:35
【问题描述】:

我今天真的需要你的帮助!我正在调试由另一个开发人员创建的旧 Objective-c 应用程序,并且有一个仅出现在 iOS 11 上的新错误。 该错误来自尝试创建“Scratch View”时使用的图像处理功能,类似于此 -> https://github.com/joehour/ScratchCard 但是,从 iOS 11 开始,该功能不再起作用,在上面的代码中,[Unknown process name] CGImageMaskCreate: invalid image provider: 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 中不再起作用?

感谢您的帮助!

【问题讨论】:

    标签: objective-c image-processing ios11


    【解决方案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 = ...
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 2016-08-11
      • 2016-08-04
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      相关资源
      最近更新 更多