2013-04-26 149 views
0

我从来没有使用System.Drawing之前,所以忍受我,因为这是我找到并放在一起的代码mich马赫。C#自定义颜色黑色

我试图与顶部的白色和底部创建一个图像另一种颜色(最终将图片添加到它)

我的代码:

 Bitmap bmp = new Bitmap(800, 800, PixelFormat.Format32bppArgb); 
     using (Graphics gfx = Graphics.FromImage((Image)bmp)) 
     { 
      gfx.FillRectangle(Brushes.Transparent, new RectangleF(0, 0, bmp.Width, bmp.Height)); 
      gfx.FillRectangle(Brushes.White, 0, 0, 800, 600); 
      gfx.FillRectangle(new SolidBrush(Color.FromArgb(21, 93, 127)), 600, 800, 0, 800); 
     } 
     bmp.Save("C:\test.jpg", ImageFormat.Bmp); 

但是我的成绩是最高的白色,底部黑色......不知道我做错了什么。

我也试过gfx.FillRectangle(new SolidBrush(System.Drawing.ColorTranslator.FromHtml("#155d7f")), 600, 800, 0, 800);

回答

3
gfx.FillRectangle(new SolidBrush(Color.FromArgb(21, 93, 127)), 600, 800, 0, 800); 

您从绘制一个矩形的坐标600,800,在0像素和800像素高度的总宽度,你可以从MSDN here看到。由于该区域未着色,因此显示为黑色。

我想你的意思做:

gfx.FillRectangle(new SolidBrush(Color.FromArgb(21, 93, 127)), 0, 600, 800, 200); 
+0

数字它只是我的坐标。谢谢你的工作。 – 2013-04-26 18:09:10

0

你必须通过正确的坐标为矩形。有关更多信息,请参阅here

gfx.FillRectangle(new SolidBrush(Color.FromArgb(21, 93, 127)), 0, 600, 800, 200);