Plex 2E

 View Only
  • 1.  Displaying an image retrieved from LDAP on a panel

    Posted Feb 19, 2015 11:52 AM


    Hi ... A C# question .... I am linking to an Active Directory containing staff details.  One of the data attributes is a jpeg photo.  Currently I am using the following to retrieve the byte data

     

    if (staffInfo.Properties["jpegphoto"].Count > 0)

    {

         byte[] picbyte = (byte[]) staffInfo.Properties["jpegphoto"][0];

      MemoryStream ms = new MemoryStream(picbyte);

        staff.Photo = System.Drawing.Image.FromStream(ms);  //where staff.Photo is defined as a System.Drawing.Image

     

    }

     

    I want to cast staff.Photo into a Plex field and display it on the panel.  I have tried blob and object datatypes and also setting the picture property on the field to no avail.

     

    The best I have managed to get to date is a field displaying the words "System.Drawing.Bitmap"

     

    Anyone done anything similar and have any suggestions?

     

    Cheers Dave.



  • 2.  Re: Displaying an image retrieved from LDAP on a panel

    Posted Feb 23, 2015 12:23 PM

    Anyone able to offer suggestions to David?

     

    Thank you



  • 3.  Re: Displaying an image retrieved from LDAP on a panel

    Posted Feb 27, 2015 05:09 AM

    Hi David -

     

    The Picture field property for a CharField expects a file name as the string value. File must be on the file system. You would need to save the jpg to disk, and then set the value of the field to that path.

     

    If we don't like the idea of storing the file on disk, we need to build a solution ourselves. One approach is a child panel where we add a control to show the picture programmatically.

     

    Best

    Lorenz



  • 4.  Re: Displaying an image retrieved from LDAP on a panel
    Best Answer

    Posted Feb 27, 2015 07:59 AM

    We can do something like this: 

     

    --- Source code ------

    #events Create WPF Image Control

    using System.Windows.Controls;

    using System.Diagnostics;

    using System.IO;

     

    // add WPF image control

    AddImageControl(this);

     

    #endevents

     

     

    #panelmethods Create WPF Image Control

     

     

     

     

     

       // Add image control to the Plex Panel

      void AddImageControl(App.UI.Image.AA4zF_ObPnl panel) {

      System.Windows.Controls.Image wb = new System.Windows.Controls.Image();

      // return a reference to the obj for further actions

      &(1:).Value = wb;

      // set some properties

      wb.Width = 300;

      wb.Height = 300;

      wb.Margin = new Thickness(100, 100, 0, 0);

      wb.HorizontalAlignment = HorizontalAlignment.Left;

      wb.VerticalAlignment = VerticalAlignment.Top;

                // load a byte array (simulation of the one you get from LDAP)

     

                try

                {

                    FileStream fs = null;

     

     

                    fs = File.OpenRead("C:\\myImage.jpg");

                    byte[] bytes = new byte[fs.Length];

                    fs.Read(bytes, 0, Convert.ToInt32(fs.Length));

     

     

                    if (fs != null)

                    {

                        fs.Close();

                        fs.Dispose();

                    }

     

     

                    // Bitmap

     

     

                    BitmapImage bmpi = new BitmapImage();

                    bmpi.BeginInit();

                    bmpi.StreamSource = new MemoryStream(bytes);

                    bmpi.EndInit();

                    // set the source to the control

                    wb.Source = bmpi;

      }

                catch (Exception ex) { System.Diagnostics.Debug.Write(ex.StackTrace); }

     

     

      // add to ObUIGrid

      ObScrollViewer obscroll = (ObScrollViewer)panel.Content;

      ObUIGrid obuigrid = (ObUIGrid)obscroll.Content;

      obuigrid.Children.Add(wb);

      Debug.WriteLine(panel.Content);

               

      }

     

     

    #endpanelmethods

    ---end source code --