c# - How to display image returned by WS? -


i request ws returns image.

 httpwebresponse response = (httpwebresponse)request.getresponse(); 

i can see in httpwebresponse contenttype image/jpeg. display image in view, don't know how. don't want write image in concrete file on hdd.
have extract httpwebresponse, have cast in byte[], in file, or so?
, how can display <img> in view, should put src, file not exist?

<img src="???" /> 

edit : i've done far :

in controller :

 ... byte[] responsebyte = null;  httpwebresponse response = (httpwebresponse)request.getresponse();  stream datastream = response.getresponsestream();  long streamlength = getstreamlength(datastream);  responsebyte = new byte[streamlength];  datastream.read(responsebyte, 0, (int)streamlength);  productdto.thumbnail = responsebyte; 

and in view :

 @{       var base64 = convert.tobase64string(@item.thumbnail);       var imgsrc = string.format("data:image/jpeg;base64,{0}", base64);   }   <img src="@imgsrc" /> 

but broken link image , @imgsrc contains

<img src="data:image/jpeg;base64,aaaaaa.....aaaaaaaaaaa"> 

finally that's i've done (that's mix of above answers , others found on others topics) :

controller:

... httpwebresponse response = (httpwebresponse)request.getresponse(); stream datastream = response.getresponsestream(); wsresponseasimg = image.fromstream(response.getresponsestream());  byte[] imgbytes = turnimagetobytearray(wsresponseasimg); string imgstring = convert.tobase64string(imgbytes); string responseimgtobase64 = string.format("data:image/jpeg;base64," + imgstring);  productdto.thumbnail = responseimgtobase64;   ...  }       private byte[] turnimagetobytearray(system.drawing.image img)     {         memorystream ms = new memorystream();         img.save(ms, system.drawing.imaging.imageformat.jpeg);         return ms.toarray();     } 

view :

... <img src="@item.thumbnail" /> ... 

thanks helping :)


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -