Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
240
Loading images
posted

How does one go about loading images into the datacarousel? 

My images are stored on SQL 2000 using the image type.  There is also a integer field for Employee ID.

The datacarousel datasource is from a LINQ query.  The EmployeeID loads fine but the images don't display I get binary numbers only. 

Parents
No Data
Reply
  • 22852
    Offline posted

    Hello,

    I believe that the images are being retrieved as a Byte[].  This needs to be converted to an image format that the XamDataCarousel can display.  You could do this conversion before you bind the data to the XamDataCarousel.

    The following code snippet will convert the images from NorthWind to a BitmapImage which can be displayed by the XamDataCarousel:

    public BitmapImage ImageFromBytes(Byte[] bytes)
    {
        MemoryStream stream = new MemoryStream();

        // to work around quirk in Northwind database:
        int offset = 78;
        stream.Write(bytes, offset, bytes.Length - offset);
        // end workaround

        BitmapImage image = new BitmapImage();
        image.BeginInit();
        image.StreamSource = stream;
        image.EndInit();
        return image;
    }

    You can use something like the above code to convert your images so that they can be displayed.

    Let me know if you have any questions with this matter.

    Alan

Children