首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于iOS 11图像数据处理的问题

关于iOS 11图像数据处理的问题
EN

Stack Overflow用户
提问于 2018-03-03 21:45:13
回答 1查看 119关注 0票数 0

今天我真的需要你的帮助!我正在调试另一个开发人员创建的一个旧的objective-c应用程序,有一个只在iOS 11上出现的新错误。这个错误来自尝试创建“临时视图”时使用的图像处理函数,类似于这个-> https://github.com/joehour/ScratchCard,但是,从iOS 11开始,该函数不再工作,在上面的代码中,我在[Unknown process name] CGImageMaskCreate: invalid image provider: NULL. <--未创建变量CGDataProviderRef dataProvider (null)时收到错误

代码语言:javascript
复制
// 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中不再起作用了吗?

感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2019-01-17 13:27:36

iOS 11已停止处理CGDataProviderCreateWithCFData(null),因此您的需要来设置pixels的长度。

类似于:

代码语言:javascript
复制
...
CFMutableDataRef pixels = CFDataCreateMutable(NULL, imageWidth * imageHeight);
CFDataSetLength(pixels, imageWidth * imageHeight); // this is the line you're missing for iOS11+
_contextMask = ...
...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49084800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档