How do I use Color[] Colors in C#? [closed]
Ok so , I found this cool code and I can't use it. You see ... We have to input an Image which I can do it 开发者_开发百科but we also need to Input Colors which I dont know how to do it...
public static Bitmap Colorize(Bitmap Image, Color[] Colors)
{
if (Colors.Length < 256)
return null;
Bitmap TempBitmap = new Bitmap(Image.Width, Image.Height);
for (int x = 0; x < Image.Width; ++x)
{
for (int y = 0; y < Image.Height; ++y)
{
int ColorUsing = Image.GetPixel(x, y).R;
TempBitmap.SetPixel(x, y, Colors[ColorUsing]);
}
}
return TempBitmap;
}
You need to pass in an array of Color objects, as follows:
Bitmap bitmapToColorize = new Bitmap(@"C:\bitmap.bmp");
Color[] colors = new Color[2];
colors[0] = Color.Blue;
colors[1] = Color.Green;
Colorize(bitmapToColorize, colors);
Of course, looking at the method, it looks like you need to fill the Color array with at least 256 colors.
I would recommend you read up on arrays.
精彩评论