目標:イメージピクセルデータがイメージピクセルを「スキャン」する方法は?
のみ黒と透明ピクセルを含む画像の左側の最初の黒画素を見つけます。
私が持っているもの:
私は(ここではそれを見つけた:https://stackoverflow.com/a/1262893/358480を):ピクセルデータを取得し、黒と透明ピクセルの配列を持ってする方法を知っている
+ (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy count:(int)count
{
NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
// Now your rawData contains the image data in the RGBA8888 pixel format.
int byteIndex = (bytesPerRow * yy) + xx * bytesPerPixel;
for (int ii = 0 ; ii < count ; ++ii)
{
NSUInteger alpha = (rawData[byteIndex + 3] * 1.0)/255.0;
byteIndex += 4;
[result addObject:[NSNumber numberWithInt:alpha]];
}
free(rawData);
return result;
}
は何ですか問題?
機能が画像を「スキャン」する順序を理解できません。
私が望むのは、画像の列だけを取得し、リスト1の非トランスペアレントピクセルを持つ最初の列を特定することです。このようにして、画像の左半透明面を切り取る方法を知りますか?
どのようにピクセルを列で取得できますか?
おかげ
シャニー