How i store the images pixels in matrix form?
Posted
by Rajendra Bhole
on Stack Overflow
See other posts from Stack Overflow
or by Rajendra Bhole
Published on 2010-03-18T07:47:58Z
Indexed on
2010/03/18
7:51 UTC
Read the original article
Hit count: 206
iphone
Hi, I developing an application in which the pixelize image i want to be store in matrix format. The code is as follows.
struct pixel { //unsigned char r, g, b,a; Byte r, g, b; int count; };
(NSInteger) processImage1: (UIImage*) image {
// Allocate a buffer big enough to hold all the pixels
struct pixel* pixels = (struct pixel*) calloc(1, image.size.width * image.size.height * sizeof(struct pixel)); if (pixels != nil) { // Create a new bitmap CGContextRef context = CGBitmapContextCreate( (void*) pixels, image.size.width, image.size.height, 8, image.size.width * 4, CGImageGetColorSpace(image.CGImage), kCGImageAlphaPremultipliedLast ); NSLog(@"1=%d, 2=%d, 3=%d", CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image),CGImageGetBytesPerRow(image)); if (context != NULL) { // Draw the image in the bitmap CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, image.size.width, image.size.height), image.CGImage); NSUInteger numberOfPixels = image.size.width * image.size.height;
I confusing about how to initialize the 2-D matrix in which the matrix store data of pixels.
© Stack Overflow or respective owner