Jonas Moens
Jonas Moens

Reputation: 11

Strengthen RGB colors using c#

I need to strengthen the RGB channel/colors with an number that the user can choose. I've got the following code , but i'm not sure that it's correct. Can somebody tell me what i can change or can do better.

int value = int.Parse(textBoxConstante.Text);

for (int y = 0; y < myPic.Height; y++)
{
    for (int x = 0; x < myPic.Width; x++)
    {
        Color c = myPic.GetPixel(x, y);
        myPic.SetPixel(x, y, Color.FromArgb(c.R * value /10, c.G * value/10, c.B * value/10));
    }
}

Upvotes: 1

Views: 232

Answers (1)

Rikon
Rikon

Reputation: 2696

I've not run your code, but I suspect you're having problems with c# lack of implicit double casting... Try rewriting it this way:

.FromArgb((int)(c.R * ((double)value /10)), [the rest wrapped the same way]

Upvotes: 1

Related Questions