我vImageHistogramCalculation
在我当前的应用程序中使用了计算图像的直方图,在某些情况下我得到了EXC_BAD_ACCESS 。我经历了如下案例 -
- (void)histogramForImage:(UIImage *)image {
vImage_Buffer inBuffer;
CGImageRef img = image.CGImage;
CGDataProviderRef inProvider = CGImageGetDataProvider(img);
CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
inBuffer.width = CGImageGetWidth(img);
inBuffer.height = CGImageGetHeight(img);
inBuffer.rowBytes = CGImageGetBytesPerRow(img);
inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData);
vImagePixelCount histogram[4][8] = {{0}};
vImagePixelCount *histogramPointers[4] = { &histogram[0][0], &histogram[1][0], &histogram[2][0], &histogram[3][0] };
vImage_Error error = vImageHistogramCalculation_ARGBFFFF(&inBuffer, histogramPointers, 8, 0, 255, kvImageNoFlags);
if (error) {
NSLog(@"error %ld", error);
}
CGDataProviderRelease(inProvider);
}
我使用了PNG格式的 iPhone 相机胶卷中的图像,并在上面的代码中手动放入 bundle 中,它工作正常。
我对 iPhone 相机胶卷中JPG格式的图像使用了相同的代码,然后出现 EXC_BAD_ACCESS 错误。
我尝试使用照片框架从相机胶卷中获取图像,然后传递给相同的代码,然后我也收到 EXC_BAD_ACCESS 错误。
我真正需要的是找到iPhone 相机胶卷所有图像的直方图。所以我无法找出为什么上面的代码对一种图像格式工作正常而对另一种图像格式失败。还有其他原因导致崩溃吗?
编辑 1-我得出的不是图像格式,它对于某些 JPG 图像也可以正常工作,但在某些情况下仍然会崩溃。我应该如何弄清楚?
参考: