0
我目前正試圖從iOS中的UIImageview中找到一些rgba值。因此,例如,我想在白色背景1-1-1
上查找所有黑色0-0-0
像素並輸出它們的座標。在iOS中檢測UIImageview /位圖中的特定RGB值
我當前的代碼(改編自另一個計算器後):
UIImage *myPicture = [UIImage imageNamed:@"somePicture.png"];
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(myPicture.CGImage));
myWidth = CGImageGetWidth(myPicture.CGImage);
myHeight = CGImageGetHeight(myPicture.CGImage);
const UInt8 *pixels = CFDataGetBytePtr(pixelData);
UInt8 blackThreshold = 10;
int bytesPerPixel_ = 4;
for(x = 0; x < myWidth; x++)
for(y = 0; y < myHeight; y++)
{
{
int pixelStartIndex = (x + (y * myWidth)) * bytesPerPixel_;
UInt8 redVal = pixels[pixelStartIndex + 1];
UInt8 greenVal = pixels[pixelStartIndex + 2];
UInt8 blueVal = pixels[pixelStartIndex + 3];
if(redVal < blackThreshold && blueVal < blackThreshold && greenVal < blackThreshold) {
NSLog(@"x coordinate = %@", x);
NSLog(@"y coordinate = %@", y);
}
}
}
}
可能有人看代碼,並提供與問候一些反饋到一個可能的解決方案?
你可以顯示一些代碼和你得到的輸出結果或錯誤嗎? –
我沒有收到任何錯誤,我只是想找到解決問題的方法。 該代碼在我發佈的鏈接上,如果你有興趣。 –
爲什麼它不工作?出了什麼問題?你有什麼嘗試? –