Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to generate a image in ASP.Net through webservice

For my new asp.net application that I am developing I would like to generate an image at runtime using a webservice (return bytes), and show this as a image using Javascript (so that I can have ajax functionality.

Any ideas how to do this?

Or any ideas as to how I can generate an image at runtime, and show it on my webpage using Ajax (must not postback), without having to save the image to any location on the hard drive?

Thanks!

like image 570
Cyril Gupta Avatar asked Dec 14 '25 19:12

Cyril Gupta


1 Answers

Instead of having the web service put an ASHX page with the querystring parameters handling the input params. Make sure the Response.Content type is image/png

This ASHX page will generates the image stream on the fly and send it to the requesting image object. With this there is no image file saved on the server.

Here is a links with full code for the ASHX .

After you have done this, in JavaScript access the image object via DOM and set/change the SRC property.

function ChangeImage(param1, param2)
{
  var url = "http://someserver/somepage.ashx?param1=" + param1 + "&param2=" + param2;
  var image1 = document.getElementById("MyImage");
  image1.src = url;
}
like image 96
Binoj Antony Avatar answered Dec 16 '25 14:12

Binoj Antony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!