xyzaijing

得到了图片数据.就能得到任意点的颜色值了. 
 
- (void*)getImageData:(UIImage*)image 

    void* imageData; 
    if (imageData == NULL)  
        imageData = malloc(4 * image.size.width * image.size.height); 
     
    CGColorSpaceRef cref = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef gc = CGBitmapContextCreate(imageData, 
                                            image.size.width,image.size.height, 
                                            8,image.size.width*4, 
                                            cref,kCGImageAlphaPremultipliedFirst); 
    CGColorSpaceRelease(cref); 
    UIGraphicsPushContext(gc); 
     
    [image drawAtPoint:CGPointMake(0.0f, 0.0f)]; 
     
    UIGraphicsPopContext(); 
    CGContextRelease(gc); 
     
    return imageData; 
}

 

 

 

 

/**
* 根据图片和颜色返回一张加深颜色以后的图片
*/
+(UIImage *)colorizeImage:(UIImage *)baseImage withColor:(UIColor *)theColor {

UIGraphicsBeginImageContext(CGSizeMake(baseImage.size.width*2, baseImage.size.height*2));

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, baseImage.size.width * 2, baseImage.size.height * 2);

CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);

CGContextSaveGState(ctx);
CGContextClipToMask(ctx, area, baseImage.CGImage);

[theColor set];
CGContextFillRect(ctx, area);

CGContextRestoreGState(ctx);

CGContextSetBlendMode(ctx, kCGBlendModeMultiply);

CGContextDrawImage(ctx, area, baseImage.CGImage);

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return newImage;


}

分类:

技术点:

相关文章: