title: Insert image into asp.net image tag
body: <p>I'm trying to display my picture out on the image tag at my webform in a web application which i used VS2012 to develop. I have already stored my image in a binary form in the sql server 2008. I attempted to display out the image through the c# codes. However, the image displayed out is the exact dimension size. I'm trying to store this particular selected into the image tag with a specific dimension. Here are my codes which i used to display out my image.</p>
  
  <p>This code here is for me to select out the picture from the database. I managed to display the picture out by using this.</p>
  
  <pre><code>string strQuery = "select profilepic from LoginRegisterOthers where username=@username";
              SqlCommand cmd = new SqlCommand(strQuery);
              cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
              DataTable dt = GetData(cmd);
              if (dt != null)
              {
                  download(dt);
              }
  </code></pre>
  
  <p>This code then used to convert the image binary data into an image.</p>
  
  <pre><code>private void download(DataTable dt)
      {
          Byte[] bytes = (Byte[])dt.Rows[0]["profilepic"];
          Response.Buffer = true;
          Response.Charset = "";
          Response.Cache.SetCacheability(HttpCacheability.NoCache);
          Response.ContentType = "image/jpg";
          //Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["Name"].ToString());
          Response.BinaryWrite(bytes);
          Response.Flush();
          Response.End();
      }
  </code></pre>