Skip to content

Instantly share code, notes, and snippets.

@Clancey
Created July 16, 2010 21:35
Show Gist options
  • Save Clancey/478946 to your computer and use it in GitHub Desktop.
Save Clancey/478946 to your computer and use it in GitHub Desktop.
Allows on the fly change the properties of an image
public static UIImage AdjustImage(RectangleF rect,UIImage template, CGBlendMode mode,float red,float green,float blue,float alpha )
{
using (var cs = CGColorSpace.CreateDeviceRGB ()){
using (var context = new CGBitmapContext (IntPtr.Zero, (int)rect.Width, (int)rect.Height, 8, (int)rect.Height*4, cs, CGImageAlphaInfo.PremultipliedLast)){
context.TranslateCTM(0.0f,0f);
//context.ScaleCTM(1.0f,-1.0f);
context.DrawImage(rect,template.CGImage);
context.SetBlendMode(mode);
context.ClipToMask(rect,template.CGImage);
context.SetRGBFillColor(red,green,blue,alpha);
context.FillRect(rect);
return UIImage.FromImage (context.ToImage ());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment