【发布时间】:2015-10-15 14:17:14
【问题描述】:
我在当前的应用程序中使用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);
}
我使用 iPhone 相机胶卷中的 PNG 格式的图像,并在上面的代码中手动放入 bundle 中,效果很好。
我对 iPhone 相机胶卷中 JPG 格式的图像使用了相同的代码,然后出现 EXC_BAD_ACCESS 错误。
我尝试使用 Photos Framework 从相机胶卷中获取图像,然后传递给相同的代码,然后我也收到 EXC_BAD_ACCESS 错误。
我真正需要的是找到 iPhone 相机胶卷的所有图像的直方图。所以我无法找出为什么上面的代码适用于一种图像格式而无法适用于其他图像格式.崩溃还有其他原因吗?
编辑 1- 我得到的不是图像格式,它对于某些 JPG 图像也可以正常工作,但在某些情况下仍然会崩溃。我应该如何解决这个问题?
参考:
Compute the histogram of an image using vImageHistogramCalculation
【问题讨论】:
-
您似乎没有分配内存来保存计算的直方图:check this answer
标签: ios objective-c image-processing photosframework vimage