【发布时间】:2014-12-20 19:40:14
【问题描述】:
我有一个 UIImagePickerViewController,用户可以在其中拍照。我的问题是如何在将照片上传到服务器之前知道用户是否发送深色照片。我的意思是完全或几乎是黑色的。
我正在研究,我发现了这个:
const UInt8 *pixels = CFDataGetBytePtr(imageData);
UInt8 blackThreshold = 10; // or some value close to 0
int bytesPerPixel = 4;
for(int x = 0; x < width1; x++) {
for(int y = 0; y < height1; y++) {
int pixelStartIndex = (x + (y * width1)) * bytesPerPixel;
UInt8 alphaVal = pixels[pixelStartIndex]; // can probably ignore this value
UInt8 redVal = pixels[pixelStartIndex + 1];
UInt8 greenVal = pixels[pixelStartIndex + 2];
UInt8 blueVal = pixels[pixelStartIndex + 3];
if(redVal < blackThreshold && blueVal < blackThreshold && greenVal < blackThreshold) {
//This pixel is close to black...do something with it
}
}
}
但是,我不知道如何应用该算法。
【问题讨论】:
标签: ios objective-c iphone image-processing uiimagepickercontroller