title: How to get image using XMLHttpRequest in javascript
body: <p>I need to show a image which is generating in another page. I am using XMLHttpRequest to get the image from that page. Not able to do this please help.</p>
  
  <p>Code Block</p>
  
  <p>This is used to get image</p>
  
  <pre><code>    Bitmap IMG = myPane.GetImage(700,700,92);
      //Bitmap finalImage = new Bitmap(800, 800);
      byte[] byteArray = new byte[0];
      using (MemoryStream stream = new MemoryStream())
      {
          IMG.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
          stream.Close();
  
          byteArray = stream.ToArray();
      }
  
      Response.Write(byteArray);
  </code></pre>
  
  <p>This is used to fetch that in javascript</p>
  
  <pre><code> function b() {
             searchReq.onreadystatechange = ProcessResponse;
             searchReq.open("GET", 'Default.aspx', true);
             if (searchReq.overrideMimeType) {
                 searchReq.overrideMimeType('text/plain; charset=x-user-defined');
             } else {
                 searchReq.setRequestHeader('Accept-Charset', 'x-user-defined');
             }
  
  
             searchReq.send(null);
         }
  
         function ProcessResponse() {
             if (searchReq.readyState == 4) {
                 if (searchReq.status == 200) {
                     retval = "";                      
                     var img = document.getElementById("myimg");
                     img.src = "data:image/jpeg;base64," +(searchReq.responseText);
                 }
             }
  
         }
  </code></pre>
  
  <p>Thanks</p>