C# Color an image with shadows

前端 未结 2 1515
刺人心
刺人心 2021-01-22 06:51

I am currently creating sort of a game with C# and am trying to create outfits for the players. I would like to make cloth design and let players chose the colors.

I too

2条回答
  •  无人共我
    2021-01-22 07:40

    You could iterate over each pixel of the bitmap and make a color shift in the direction you want. When I say colorshoft I mean a you have to adapt the RGB values of each pixel.

    A simple shift to red could look like this:

    for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
    {
        for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
        {
            //get color of the pixel
            Color pixelColor = myBitmap.GetPixel(Xcount, Ycount);
            byte red = pixelColor.R;
            byte green = pixelColor.G;
            byte blue = pixelColor.B;
    
            //make shift and prevent overflow
            if (red < 205)
                red += 50;
            else
                red = 255;
    
            //set color of the pixel
            myBitmap.SetPixel(Xcount, Ycount, Color.FromRgb(red, green, blue));
        }
    }
    

    Keep in mind this is just a simple example and may not result in what you expected. You can read more about the RGB colorspace here: RGB color model and here you find a RGB Color Codes Chart

提交回复
热议问题