private void VariableTable_BinaryDataChanged(BinaryStateChangeNotification bscn) { if (bscn.State != _imageState.DataName) { return; } // if we get here, we are interested in the message if (bscn.HasBinaryData()) { // we need to try to create an image from the binary data try { if (ImageSmartCIO.IsTypeSupported(bscn.ContentType)) { _imageDrawer.Image = new Bitmap(bscn.BinaryData); } } catch (Exception) { Globals.GetFrame(_imageState.Appliance) .AddLogLine("Couldn't process binary image file for " + _imageState.DataName + "."); } } else { // send a state-value-request to get the new binary value // if supported, send the height and width that we desire try { StateValueRequest svrqst = new StateValueRequest(_imageState.DataName); if (((BinarySpace)_imageState.Type.ValueSpace)[SCALABLE_IMAGE_OPT] != null) { svrqst[StateValueRequest.DESIRED_WIDTH_OPT] = _imageDrawer.Width.ToString(); svrqst[StateValueRequest.DESIRED_HEIGHT_OPT] = _imageDrawer.Height.ToString(); } if (ImageSmartCIO.IsTypeSupported(bscn.ContentType)) { _imageState.Appliance.GetConnection().Send(svrqst); _imageDrawer.Image = ThumbnailViewer.NO_IMAGE; } } catch (Exception) { } } }
private void VariableTable_BinaryDataChanged(BinaryStateChangeNotification bscn) { int imageIndex = -1; // TODO: Determine if this a message for the image state we're interested in, // and get the index within the list for later try { string state = bscn.State; if (!state.EndsWith(_imageState.DataWindow)) { return; } // -2 to remove separator char and ']' state = state.Substring(0, state.Length - _imageState.DataWindow.Length - 2); int startIdx = state.LastIndexOf("["); if (startIdx < 0) { return; } // + 1 to remove '[' state = state.Substring(startIdx + 1); // -1 because list indices are 1-indexed imageIndex = Int32.Parse(state) - 1; } catch (Exception) { return; } // if we get here, we are interested in the message if (bscn.HasBinaryData()) { // we need to try to create an image from the binary data try { System.Drawing.Image img = null; if (ImageSmartCIO.IsTypeSupported(bscn.ContentType)) { img = new Bitmap(bscn.BinaryData); } if (((BinarySpace)_imageState.Type.ValueSpace)[ImageSmartCIO.SCALABLE_IMAGE_OPT] != null && ((ThumbnailViewer)_control)[imageIndex] != ThumbnailViewer.NO_IMAGE && (img.Width > ThumbnailViewer.THUMBNAIL_WIDTH || img.Height > ThumbnailViewer.THUMBNAIL_HEIGHT)) { return; } ((ThumbnailViewer)_control)[imageIndex] = img; } catch (Exception) { Globals.GetFrame(_imageState.Appliance) .AddLogLine("Couldn't process binary image file for " + bscn.State + "."); } } else { // send a state-value-request to get the new binary value // if supported, send the height and width that we desire try { ((ThumbnailViewer)_control)[imageIndex] = null; StateValueRequest svrqst = new StateValueRequest(bscn.State); if (((BinarySpace)_imageState.Type.ValueSpace)[ImageSmartCIO.SCALABLE_IMAGE_OPT] != null) { svrqst[StateValueRequest.DESIRED_WIDTH_OPT] = ThumbnailViewer.THUMBNAIL_WIDTH.ToString(); svrqst[StateValueRequest.DESIRED_HEIGHT_OPT] = ThumbnailViewer.THUMBNAIL_HEIGHT.ToString(); } if (ImageSmartCIO.IsTypeSupported(bscn.ContentType)) { _imageState.Appliance.GetConnection().Send(svrqst); } } catch (Exception) { } } }