2011-07-03 32 views
-3

好吧,我发现这个很酷的代码,我无法使用它。你看......我们要输入的图像 ,我能做到这一点,但我们还需要输入颜色,我不知道该怎么做...如何在C#中使用Color []颜色?

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; 
} 
+0

想知道这段代码应该做什么很有趣。 –

+0

@Etienne:难道不明显吗?它做了“着色”。 :D但是,严重的是,它看起来像使用不同的调色板将一些图像重新绘制成新图像。 –

+3

@Cody:你在说什么? – BoltClock

回答

2

你需要的数组传递颜色对象如下:

 Bitmap bitmapToColorize = new Bitmap(@"C:\bitmap.bmp"); 
     Color[] colors = new Color[2]; 
     colors[0] = Color.Blue; 
     colors[1] = Color.Green; 

     Colorize(bitmapToColorize, colors); 

当然,看看这个方法,看起来你需要用至少256种颜色填充颜色数组。

我会建议你阅读arrays

+0

当然,数组至少应该是Color [256],所以该方法不会返回null。但这似乎是提问者寻找的答案。 +1 – Tod

+0

好吧,那么我不得不为什么要返回null? – Pedrum

+0

您需要使用256色的数组。 –

相关问题