How i store the images pixels in matrix form?
- by Rajendra Bhole
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.