title: How to retrieve binary image from database using C# in ASP.NET
body: <p>I need to retrieve a binary image from the database.</p>
  
  <p>My queries are as below.</p>
  
  <pre><code>SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=MyGames;Integrated Security=True");
  SqlCommand cmd = new SqlCommand("Select blueBallImage from CorrespondingBall WHERE objective = Default Ball", con);
  </code></pre>
  
  <p>I do not know how to retrieve blueBallImage which is a binary image.</p>
  
  <p>After I have retrieve it successfully, I need to add a text onto the image using a dropdownlist which contain the text. The codes are as below.</p>
  
  <pre><code>Bitmap bmp = new Bitmap(@"C:\Users\apr13mpsip\Documents\Visual Studio 2012\WebSites\CorrespondingBallWebSite\Images\blueBallDefault.png");
  </code></pre>
  
  <p>For the time being, I do not know how to retrieve the image. Therefore, I hard coded it which I do not want. I want to retrieve it from database.</p>
  
  <pre><code>Graphics gra = Graphics.FromImage(bmp);
  
  gra.DrawString(ddlCharacter.Text, new Font("Verdana", 18), Brushes.Black, new PointF(4, 6));
  
  MemoryStream ms1 = new MemoryStream();
  bmp.Save(ms1, ImageFormat.Png);
  var base64Data = Convert.ToBase64String(ms1.ToArray());
  imgImage.ImageUrl = "data:image/png;base64," + base64Data;
  </code></pre>