現在、iOS の UIImageview からいくつかの rgba 値を見つける方法を見つけようとしています。たとえば、0-0-0
白い背景にあるすべての黒いピクセルを見つけて1-1-1
、それらの座標を出力したいとします。
私の現在のコード(別のstackoverflow投稿から適応):
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);
}
}
}
}
誰かがコードを見て、考えられる解決策についてフィードバックを提供できますか?