how to initialize and implement the matrix inside the function in objective-C?
- by Rajendra Bhole
Hi,
I want to develop an application in which i want to be initialize the matrix for manipulation. The code as follows,
struct pixel
{
Byte r, g, b,a;
int count;
};
(NSInteger) processImage1: (UIImage*) image
{
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
);
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;
while (numberOfPixels > 0) {
if (pixels->r == 254 || pixels->g == 77 || pixels->b==254) {
numberOfRedPixels++;
}
pixels++;
numberOfPixels--;
}
CGContextRelease(context);
}
free(pixels);
}
return 1;
}
I want to implement the matrix inside the function of
- (NSInteger) processImage1: (UIImage*) image
{}
The matrix should have be row = image.size.width
and column = image.size.height.