Note that there are some explanatory texts on larger screens.

plurals
  1. POHow image pixel data "scans" the image pixels?
    text
    copied!<p><strong>The Goal:</strong></p> <p>Finding the first black pixel on the left side of an image that contains black and transparent pixels only.</p> <p><strong>What I have:</strong></p> <p>I know how to get the pixel data and have an array of black and transparent pixels (found it here : <a href="https://stackoverflow.com/a/1262893/358480">https://stackoverflow.com/a/1262893/358480</a> ):</p> <pre><code>+ (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 &lt; count ; ++ii) { NSUInteger alpha = (rawData[byteIndex + 3] * 1.0) / 255.0; byteIndex += 4; [result addObject:[NSNumber numberWithInt:alpha]]; } free(rawData); return result; } </code></pre> <p><strong>What is the problem ?</strong></p> <p>I can not understand the order which the function "scans" the image. </p> <p>What i want is to get only the columns of the image and locate the first column that has at list 1 non-transperant pixel. this way I will know how to crop the left, transparent side of the image?</p> <p>How can I get the pixels by columns?</p> <p>Thanks</p> <p>Shani</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload