tags:

views:

42

answers:

0

Hi, i develop the code in which i cropping the UIImage but in follwing code will not cropping the image.Also it not give me any error, is their any mistake in my code that why i not getting cropping image in following method of -(UIImage)cropedImag

  • (UIImage *) cropedImage: (UIImage *) image { CGFloat width = image.size.width; CGFloat height = image.size.height; UIImage *cropedImage = [[UIImage alloc] init]; CGFloat widthCrop = width/2; CGFloat heightCrop = height/2; CGRect cropRect = CGRectMake(widthCrop, heightCrop, widthCrop, heightCrop); [cropedImage drawInRect:cropRect]; return cropedImage;

} - (NSInteger) processImage1: (UIImage*) cropedImage {

CGFloat widthCrop =  cropedImage.size.width;
CGFloat heightCrop = cropedImage.size.height;
NSLog( @"Get image width %g",widthCrop);
NSLog( @"Get image height %g",heightCrop);

// Allocate a buffer big enough to hold all the pixels
struct pixel* pixels = (struct pixel*) calloc(1, cropedImage.size.width * cropedImage.size.height * sizeof(struct pixel));
if (pixels != nil)
{
    // Create a new bitmap
    CGContextRef context = CGBitmapContextCreate(
                                                 (void*) pixels,
                                                 cropedImage.size.width,
                                                 cropedImage.size.height,
                                                 8,
                                                 cropedImage.size.width * 4,
                                                 CGImageGetColorSpace(cropedImage.CGImage),
                                                 kCGImageAlphaPremultipliedLast
                                                 );
    if (context != NULL)
    {
        // Draw the image in the bitmap
        CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, cropedImage.size.width, cropedImage.size.height), cropedImage.CGImage);
        NSUInteger numberOfPixels = cropedImage.size.width * cropedImage.size.height;

        NSMutableArray *numberOfPixelsArray = [[[NSMutableArray alloc] initWithCapacity:numberOfPixelsArray] autoreleas