RadBinaryImage ASP.NET AJAX

1 Answer 195 Views
BinaryImage Grid UI for ASP.NET AJAX in ASP.NET MVC
Rob
Top achievements
Rank 2
Iron
Iron
Iron
Rob asked on 11 Jan 2023, 09:26 PM

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;

        }
Cheers, Rob.

 

Rumen
Telerik team
commented on 16 Jan 2023, 01:43 PM

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.

1 Answer, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 2
Iron
Iron
Iron
answered on 17 Jan 2023, 12:46 AM

Thanks for the response ... I was able to resolve ... needed a byte[] array.

Cheers, Rob.

Tags
BinaryImage Grid UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Rob
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Rob
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or