I've been trying to display a System.Drawing.Image (obtained from live camera feed snapshot) dynamically in a DataList control with asp:Image control but not having any success.
I was looking at RadBinaryImage to see if this is a viable option.
The images to be displayed are variable (aka dynamic number of images not static number/count) so I may have 5 images or 10 images or 7 images that are all System.Drawing.Image types. I want to display those images in a Grid or DataList.
<asp:DataList ID="cameras" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" RepeatLayout="Table">
<ItemTemplate>
<asp:Image ID="cameraX" runat="server" />
</ItemTemplate>
</asp:DataList>
In the ItemDataBound event handler I convert to byte array and assign to asp:Image ImageUrl ... but this results in nothing being displayed. No errors, just nothing displayed. Would RadBinaryImage be a solution?
protected void cameras_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Models.Facility.Camera camera = e.Item.DataItem as Models.Facility.Camera;
Image img = GetImage(camera);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
System.Web.UI.WebControls.Image imgControl = (System.Web.UI.WebControls.Image)e.Item.FindControl("camera");
var base64Data = Convert.ToBase64String(ms.ToArray());
imgControl.ImageUrl = "data:image/jpg;base64," + base64Data;
}
I am not familiar with the API, provided and supported by the web camera vendor, but you can insert a break point in the ItemDataBound event and see if the GetImage(camera) returns contains a real (valid) image data prior to saving or converting it to a base64 string.
If the code does not work with a regular and simple asp:Image control then the chance to work with RadBinaryImage is low too.