polaroid filter from UIImage

前端 未结 2 1679
野的像风
野的像风 2020-12-30 17:15

I am trying to implement some image filters, like polaroid, in iphone. I searched on how to filter an existing UIImage to convert it into a polaroid style and come across th

相关标签:
2条回答
  • 2020-12-30 17:52
         int step=10;// variable value that changes the level of saturation
    
    int red = pixelRedVal;
    int green = pixelGreenVal;
    int blue = pixelBlueVal;
    
    int avg = (red + green + blue) / 3;
    
    pixelBuf[r] = SAFECOLOR((avg + step * (red - avg)));
    pixelBuf[g] = SAFECOLOR((avg + step * (green - avg)));
    pixelBuf[b] = SAFECOLOR((avg + step * (blue - avg)));
    where SAFECOLOR is a macro
    
    define SAFECOLOR(color) MIN(255,MAX(0,color))
    and for Brightness int step=10;// variable value that changes the level of saturation
    
    int red = pixelRedVal;
    int green = pixelGreenVal;
    int blue = pixelBlueVal;
    
    
    pixelBuf[r] = SAFECOLOR(red * step);
    pixelBuf[g] = SAFECOLOR(green * step);
    pixelBuf[b] = SAFECOLOR(blue * step);
    
    
    
    
    You can simply use this: with different parameters
    
    // Note: the hue input ranges from 0.0 to 1.0, both red.  Values outside this range will be clamped to 0.0 or 1.0.
        //Polaroid with HSB parameter
    
       - (UIImage*) polaroidishEffectWithHue:(CGFloat)hue saturation:(CGFloat)sat brightness:(CGFloat)bright  alpha:(CGFloat)alpha
      {
    
       // Find the image dimensions.
        CGSize imageSize = [self size];
        CGRect imageExtent = CGRectMake(0,0,imageSize.width,imageSize.height);
    
        // Create a context containing the image.
        UIGraphicsBeginImageContext(imageSize);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [self drawAtPoint:CGPointMake(0,0)];
    
        // Draw the hue on top of the image.
        CGContextSetBlendMode(context, kCGBlendModeHue);
        [[UIColor colorWithHue:hue saturation:sat brightness:bright alpha:alpha] set];
        UIBezierPath *imagePath = [UIBezierPath bezierPathWithRect:imageExtent];
        [imagePath fill];
    
        // Retrieve the new image.
        UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return result;
    }
    
    0 讨论(0)
  • 2020-12-30 18:04

    This might be helpful, from Camera+ taking filters from photoshop and reproducing them for iOS.

    http://taptaptap.com/blog/creating-a-camera-plus-fx/

    0 讨论(0)
提交回复
热议问题