Friday, 24 February 2012

uiimage+extra classes for the brightness,contrast,sepia and more + iphone

//For the uiimage+extra classes for the brightness and contrast

https://github.com/coryleach/UIImageAdjust

//For the uiimage sepia and more

https://github.com/Nyx0uf/NYXImagesUtilities/tree/master/Categories

2 comments:

  1. -(UIImage*)imageWithColor:(UIColor*)color image:(UIImage*)img {
    UIGraphicsBeginImageContext(img.size);
    CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetBlendMode(context, kCGBlendModeColor);
    [img drawInRect:rect];

    [color set];
    CGContextAddRect(context, rect);
    CGContextFillPath(context);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIImage *maskImage = img;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGImageRef maskImageRef = [maskImage CGImage];
    // create a bitmap graphics context the size of the image
    CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);


    if (mainViewContentContext==NULL)
    return NULL;

    CGFloat ratio = 0;

    ratio = maskImage.size.width/ image.size.width;

    if(ratio * image.size.height < maskImage.size.height) {
    ratio = maskImage.size.height/ image.size.height;
    }

    CGRect rect1 = {{0, 0}, {maskImage.size.width, maskImage.size.height}};
    CGRect rect2 = {{-((image.size.width*ratio)-maskImage.size.width)/2 , -((image.size.height*ratio)-maskImage.size.height)/2}, {image.size.width*ratio, image.size.height*ratio}};


    CGContextClipToMask(mainViewContentContext, rect1, maskImageRef);
    CGContextDrawImage(mainViewContentContext, rect2, image.CGImage);


    // Create CGImageRef of the main view bitmap content, and then
    // release that bitmap context
    CGImageRef newImage = CGBitmapContextCreateImage(mainViewContentContext);
    CGContextRelease(mainViewContentContext);

    UIImage *theImage = [UIImage imageWithCGImage:newImage];

    CGImageRelease(newImage);
    UIGraphicsEndImageContext();
    // return the image
    return theImage;

    }

    ReplyDelete
  2. For coloring image with any color in iphone

    ReplyDelete