|
Question : Setting Brush as a Hex Color
|
|
Hi,
I have a project where I'm trying to generate page titles on the fly. The problem is that I have to set the color too. I have Brushes.Black or Brushes. Orange at my disposal, but I'd really like to be able to set the font color by hex value. Any suggestions?
Here's what I have so far...
Bitmap objBMP = new Bitmap(490, 30); Graphics objGraphics = Graphics.FromImage(objBMP); objGraphics.Clear(Color.White); Font objFont = new Font("Arial", 16, FontStyle.Bold); objGraphics.DrawString(strText, objFont, Brushes.Black, 10, 4); objBMP.Save(Server.MapPath("~/images/title.gif"));
Thanks for any help
EJ
|
|
Answer : Setting Brush as a Hex Color
|
|
Pass the color returned by FromHtml() to the SolidBrush() constructor:
Dim hexCol As String = "#294F96" Dim sb As New SolidBrush(System.Drawing.ColorTranslator.FromHtml(hexCol)) ' use "sb".... sb.Dispose()
In C#:
string hexCol = "#294F96"; SolidBrush sb = new SolidBrush(System.Drawing.ColorTranslator.FromHtml(hexCol)); // use "sb".... sb.Dispose();
|
|
|
|