Friday, June 10, 2016

Dynamically stream image to webform

Dynamically stream image to Panel control in WebForm

1.) Convert Stream to byte[] buffer
byte[] buffer = new byte[pd.Stream.Length];
pd.Stream.Read(buffer, 0, buffer.Length);


2.) Dynamically create Image control and set the ImageURL to the buffer
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = "data:image/tiff;base64," + Convert.ToBase64String(content, 0, content.Length);

 3.) Add Image control to the Panel
 DisplayPanel.Controls.Add(img);



 

No comments: