Is it possible that I can send image data from server side to client using JSON format and assign that data into image control.
if yes, then How??
Thanks...
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jaganathan BantheswaranPosted Dec 13, 2013, 11:55 AM
Yes, you can, but as a string. The below method converts the image bytes to string.
private string CreateBase64Image(byte[] fileBytes)
{
Image streamImage;
using (MemoryStream ms = new MemoryStream(fileBytes))
{
streamImage = ScaleImage(Image.FromStream(ms));
}
using (MemoryStream ms = new MemoryStream())
{
streamImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return Convert.ToBase64String(ms.ToArray());
}
}
And in client side,
$('#image1').attr('src', 'data:image/png;base64,' + imageString);