Johan Karlsson
Johan Karlsson

Reputation: 928

Drawing an image with a color tint in MonoTouch

What do I need to read up on to tint the image I draw with a predefined color. Alternatively just adjust the alpha value? I've played around with BlendMode but I basically don't know what I'm doing. :)

Simplyfied code below

_backgroundImage = UIImage.FromFile ("whiteblock.png"); 

var ctx = UIGraphics.GetCurrentContext ();

// What do I do here to tint or adjust alpha of the image       
ctx.DrawImage (rect, _backgroundImage.CGImage);

Thanks

AnkMannen

Upvotes: 0

Views: 179

Answers (1)

Jacob Foshee
Jacob Foshee

Reputation: 2773

I recommend starting with the Core Image Filter reference docs (see also CIFilter).
(Note that depending on the version of the OS, not all filters may be available.)

You probably want to focus on the filters in the CICategoryColorAdjustment category. In particular, the CITemperatureAndTint filter can adjust the tint of the image, as you ask. But, it is not straightforward to use.* There are other questions on StackOverflow describing it, like this one: Input parameters of CITemperatureAndTint (CIFilter)

Finally check out the MonoTouch docs for a code example with CITemperatureAndTint. (I believe the image attached to the examples given there are wrong, as they show a scaled image, not a tinted image.)

*It takes two parameters, each a 2D CIVector. I believe the first component of the vector is temperature and should be in the ballpark of (1k ... 30k). I believe the second component is wavelength, so in the ballpark of (380 ... 700). If someone knows better, correct me.

Upvotes: 1

Related Questions