[Solved] Apply HexaDecimal Color code into Image object in C# .Net

Last Reply on May 25, 2015 01:51 AM By Mudassar

Posted on May 25, 2015 01:50 AM

My Handler.aspx Code is given below:

protected void Page_Load(object sender, EventArgs e)
    {
        string colorCode = Request.QueryString["color_code"];
        using (System.Drawing.Bitmap bitMap = new System.Drawing.Bitmap(150, 80))
        {
            if (colorCode != "")
            {
                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitMap))
                {
                    System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml("#" + colorCode));
                    graphics.FillRectangle(brush, 0, 0, bitMap.Width, bitMap.Height);
                }
                bitMap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            Response.End();
        }
    }

My Code Behind code is given below:

 

 foreach(DateTime date in GetDateRange(startTime,estimatedTime))
        {
            //str = str + "<div class='progress-bar progress-bar-success' role='progressbar' style='width:" + pervalue + "%'; title=" + date.ToShortDateString() + ">" + f1 + "%</div>";
            str = str + "<asp:Image ID='Image2' AlternateText=" + date.ToShortDateString() + " runat='server' ImageUrl='~/Handler.aspx?color_code=5cb85c' width=" + pervalue + "%' />";
            f1 = f1 +f;
        }

here 

ImageUrl='~/Handler.aspx?color_code=5cb85c' is not working for me. What i should make changes in the above code. Please guide me.