2013-04-26 119 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);