GetCurrentDisplayedImageAsBitmap return null

Hi,

in my plugin i use the function GetCurrentDisplayedImageAsBitmap()

System.Drawing.Bitmap bit2 = null;    
...
ImageViewerAddOn imageViewer = viewer_list[camera.FQID];
...
bit2 = imageViewer.GetCurrentDisplayedImageAsBitmap(true);
                      

bitmap is often empty.

Why?

I cannot see how you populate the viewer_list and I have a suspicion that it could be a wrong entry.

GetCurrentDisplayedImageAsBitmap will only work when an image is displayed, are you able to see that the image is displayed at the time where this is triggered?

Perhaps you can elaborate on when this is called, is it on user action when viewing something interesting or something else?

Hi,

viewer_list is populate in BackgroundPlugin inherited class:

public class MyBackgroundPlugin : BackgroundPlugin

{

   …

  **public Dictionary<FQID, ImageViewerAddOn> viewer\_list;**

   …..

  _public override void Init(){_

          …

           ClientControl.Instance.NewImageViewerControlEvent += Instance\_NewImageViewerControlEvent;

         **viewer\_list** = new Dictionary<FQID, ImageViewerAddOn>();

           …

  _}_

   _private void Instance\_NewImageViewerControlEvent(ImageViewerAddOn imageViewerAddOn)_

   _{_

       try

       {

           **viewer\_list**.Add(imageViewerAddOn.CameraFQID, imageViewerAddOn);

           …

            var button = new Button()

           {

               Content = simpleImage,

               …

               Tag = imageViewerAddOn.CameraFQID,

           };

           imageViewerAddOn.ActiveElementsOverlayAdd(new List<FrameworkElement> { button },

               new ActiveElementsOverlayRenderParameters() { FollowDigitalZoom = false, ShowAlways = true, ZOrder = 1 });

           button.Click += Button\_Click;

       }catch{

        }

   _}_

    _private void Button\_Click(object sender, RoutedEventArgs e){_

                _…_

              _Button button = (Button)sender;_

              _FQID \_FQID = button.Tag as FQID;_

              _Item camera = Configuration.Instance.GetItem(\_FQID);_

              System.Drawing.Bitmap bit2 = null;   

                ...

              ImageViewerAddOn imageViewer = viewer\_list\[camera.FQID\];

              ...

              bit2 = imageViewer.GetCurrentDisplayedImageAsBitmap(true);

    _}_

}

I Hope that now it’s more clearly.

From your comment I conclude that the answer to the question: “GetCurrentDisplayedImageAsBitmap will only work when an image is displayed, are you able to see that the image is displayed at the time where this is triggered?”

Is that you do not know if an image is displayed, or some sort of error text is displayed instead. The simplest explanation is that the camera is failing at the time you use the GetCurrentDisplayedImageAsBitmap.

I hope your plugin is coded to handle a null value in a meaningful way, otherwise this might be something you need to change.

“The simplest explanation is that the camera is failing at the time you use the GetCurrentDisplayedImageAsBitmap.”

In this plugin i capture the snapshot with two way (to check for zoom):

  • BitmapVideoSource
BitmapVideoSource _bitmapVideoSource = new BitmapVideoSource(my_camera);
_bitmapVideoSource.Init();
BitmapData bit = (BitmapData)_bitmapVideoSource.GetNearest(my_datetime);
  • GetCurrentDisplayedImageAsBitmap (as written above).
 System.Drawing.Bitmap bit2 = imageViewer.GetCurrentDisplayedImageAsBitmap(true);

BitmapVideoSource return always image but GetCurrentDisplayedImageAsBitmap only sometimes.

Could it be a camera problem?

Yes.

BitMapVideoSource.GetNearest() is very resilient, it will find an image if anything has been recorded. Note that the resilience comes from the flexibility that the nearest image might not be very near, if the camera was failing for an hour, it will just find an image outside that period.

In comparison the ImageViewerWpfControl is designed to turn black and give an error text after a period of failure to get images, when the control is reporting error it will return null on GetCurrentDisplayedImageAsBitmap().