Wijmo: Display Binary Images in Carousel Control
Carousel control in Wijmo suite provides us the ability to dynamically display text, images, controls, and more over web browsers. Typically users display images by directly providing the ImageUrl to the Carousel control and the images are then loaded onto the browser. However there might be cases when a user may want to directly pull the images from a database and then display them in the Carousel. This implementation provides a demonstration to display images from a local data source in the Carousel Control. So the first thing which we would want to do is to find a way to pull the images which are saved in the database. Using a Web Service would be the best option to do this. Since the images are saved in the binary format, we would need to convert them to an image file so that they can be displayed correctly. Since the ImageUrl property of the Carousel control only accepts a URL therefore we are using a WCF service here whose URL would be used to populate the control. To begin with, write a function to get the image:
For this blog implementation, OLEDB data source and Nwind database have being used. Images retrieved from the data source in the form of Byte array is used to create the memory stream. It is important to note here that there is a default OLE Header offset of size 78 for Northwind images and therefore we need to strip it off while creating the stream. The GetImage method is overloaded to accept the record index so that we can use it to display a particular image. Next we would need to create an OperationContract in the service Interface to call the GetImage method we created earlier.
In addition to this, we will also need to specify the WebServiceHostFactory in the service markup as displayed below:
The final step involves adding content to the C1Carousel control. So in the ImageUrl property we will specify the service URL and the image index which we need to display. So it will look something like:
Refer to the attached samples for complete implementation. Note: Please modify the connection string to correct the location of the Nwind.mdb database path as installed in your local machine. Attached samples uses the location C:\Data. BinaryImages_C# BinaryImages_VB.NET