humm... now i'm getting confused. that method returns an array of UIColor objects for each pixel in the CGImage. but how am i receiving the object atX:andY by imputing those values into the method? if i'm searching for a read-only value to output an NSLog of [UIColor colorWithRed:green:blue:alpha], where do i get that from? *head is swimming*
clearly i'm missing something fundamental here. On Sun, Nov 29, 2009 at 8:26 PM, Waqar Malik <wmal...@gmail.com> wrote: > Yes, that is then number of pixels, but do you really need that, as the width > and height would be the same, check those values as well. > > --Waqar > On Nov 29, 2009, at 5:13 PM, Chunk 1978 wrote: > >> humm... while i understand most of this method, i don't understand >> what is passed as "count"? i understand that this will convert a >> UIImage into a CGImage, and store each pixel of the image into an >> array, which are indexed by "xx" and "yy" variables. but what is >> count? is count the total number of pixels of the passed image? >> >> –––––––––– >> + (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) >> { >> CGFloat red = (rawData[byteIndex] * 1.0) / 255.0; >> CGFloat green = (rawData[byteIndex + 1] * 1.0) / 255.0; >> CGFloat blue = (rawData[byteIndex + 2] * 1.0) / 255.0; >> CGFloat alpha = (rawData[byteIndex + 3] * 1.0) / 255.0; >> byteIndex += 4; >> >> UIColor *acolor = [UIColor colorWithRed:red green:green >> blue:blue alpha:alpha]; >> [result addObject:acolor]; >> } >> >> free(rawData); >> >> return result; >> } >> –––––––––– >> >> so could if i had an image of a tree called "tree.png" that's 50 >> pixels in width, and 100 pixels in height, and i want the RGBA color >> data of the second last pixel of the last row of pixels, would i call >> it like this: >> >> –––––––––– >> [self getRGBAsFromImage:[UIImage imageNamed:@"tree.png"] atX:49 >> andY:100 count:(50*100)]; >> –––––––––– >> >> >> >> On Sun, Nov 29, 2009 at 1:28 PM, Chunk 1978 <chunk1...@gmail.com> wrote: >>> >>> precisely! thanks for this. >>> >>> On Sun, Nov 29, 2009 at 1:24 PM, Waqar Malik <wmal...@gmail.com> wrote: >>>> >>>> I think this is what you are looking for. >>>> >>>> <http://stackoverflow.com/questions/448125/how-to-get-pixel-data-from-a-uiimage-cocoa-touch-or-cgimage-core-graphics> >>>> >>>> On Nov 29, 2009, at 10:17 AM, Chunk 1978 wrote: >>>> >>>>> what method, or combination of methods can i use to receive color >>>>> information of a CGPoint. i can get basic coordinates of a view using >>>>> UITouch's locationInView method, but i'd like to get an RGBA color >>>>> information output. what methods or example code from apple should i >>>>> research? >>>>> > > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com