画像をどこかカスタムカラーで塗りつぶす必要があります。Graphics.FillRectangleメソッドはBrushでのみ塗りつぶせるようです。ただし、通常の Brush は Brushes で定義された Brush です。どうすればよいでしょうか?
Google には 2 つの方法があります:
1. 新しい SolidBrush で塗りつぶします。
public void FillByColor(Rectangle rect,Color c,Graphics G){ G.FillRectangle(new SolidBrush(c), rect);}
参考記事:「線形グラデーションを作成する方法」
2. API を使用して、閉じた領域を指定した色で塗りつぶします (テストされていません)
APIを使用して指定された色の塗りつぶしを実装する
System.Runtime.InteropServices を使用します。[DllImport("gdi32.dll")]public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);[DllImport("gdi32.dll")]public static extern IntPtr CreateSolidBrush(int crColor); [DllImport("gdi32.dll")]public static extern bool ExtFloodFill(IntPtr hdc, int nXStart, int nYStart, int crColor, uint fuFillType);[DllImport("gdi32.dll")]public static extern bool DeleteObject(IntPtr hObject );[DllImport("gdi32.dll")]public static extern int GetPixel(IntPtr hdc, int x, int y);public static uint FLOODFILLBORDER = 0;public static uint FLOODFILLSURFACE = 1;private void button1_Click(object sender, EventArgs e){ Graphics vGraphics = Graphics.FromHwnd(Handle); vGraphics.DrawRectangle(Pens.Blue, new Rectangle(0, 0, 300, 300)); ) , 300)); IntPtr vDC = vGraphics.GetHdc(); IntPtr vBrush = CreateSolidBrush(ColorTranslator.ToWin32(Color.Red)); IntPtr vPreviouseBrush (vDC, 10, GetPixel() vDC , 10, 10)、FLOODFILLSURFACE); SelectObject(vDC, vPreviouseBrush);
参考記事: http://www.csharpwin.com/csharpspace/9115r3566.shtml
(この記事の出典: http://www.cnblogs.com/allanswolf/archive/2010/04/22/1718217.html )