public CallTypeViewModel(String callType, String callImage, int imageSize) { try { Logging.LogMethodCall(MethodBase.GetCurrentMethod().DeclaringType.Name, () => new Dictionary <String, Object> { { nameof(callType), callType } , { nameof(callImage), callImage } }); var match = AvlGroupViewModel.VPImageReg.Match(callImage); CallTypeActive = true; if (!match.Success) { return; } CallTypeImageJson = PictureSymbol.GetPictureMarkerSymbolJson(match.Groups[2].Value, match.Groups[1].Value, 0, imageSize, imageSize); using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(match.Groups[2].Value))) { var image = Image.FromStream(ms); var bmp = image as Bitmap; if (bmp != null) { _originalCallImage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); var gbmp = new Bitmap(bmp.Width, bmp.Height); for (var i = 0; i < bmp.Width; i++) { for (var j = 0; j < bmp.Height; j++) { var originalColor = bmp.GetPixel(i, j); var grayScale = (originalColor.R + originalColor.G + originalColor.B) / 3; var pixelColor = System.Drawing.Color.FromArgb(originalColor.A, grayScale, grayScale, grayScale); gbmp.SetPixel(i, j, pixelColor); } } _deactivatedCallImage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( gbmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } } CallTypeValue = callType; } catch (Exception ex) { var message = "Error initializing CallTypeViewModel"; ErrorHelper.OnError(MethodBase.GetCurrentMethod().DeclaringType.Name, message, ex); Logging.LogMessage(Logging.LogType.Error, message, ex); } }
public AvlGroupViewModel(String groupName, int groupId, String groupColor, String groupImage, int imageSize) { try { Logging.LogMethodCall(MethodBase.GetCurrentMethod().DeclaringType.Name, () => new Dictionary <String, Object> { { nameof(groupName), groupName } , { nameof(groupId), groupId } , { nameof(groupColor), groupColor } , { nameof(groupImage), groupImage } , { nameof(imageSize), imageSize } }); Visible = true; Expanded = true; GroupName = groupName; GroupID = groupId; var colors = groupColor.Split(','); GroupColor = new SolidColorBrush(Color.FromArgb(byte.Parse(colors[3]), byte.Parse(colors[0]), byte.Parse(colors[1]), byte.Parse(colors[2]))); var match = VPImageReg.Match(groupImage); if (!match.Success) { return; } GroupImageJson = PictureSymbol.GetPictureMarkerSymbolJson(match.Groups[2].Value, match.Groups[1].Value, 0, imageSize, imageSize); var test = match.Groups[1].Value; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = new MemoryStream(System.Convert.FromBase64String(match.Groups[2].Value)); bi.EndInit(); GroupImage = bi; _avlUnits = new ObservableCollection <AvlViewModel>(); } catch (Exception ex) { var message = "Error initializing Avl Group View Model"; ErrorHelper.OnError(MethodBase.GetCurrentMethod().DeclaringType.Name, message, ex); Logging.LogMessage(Logging.LogType.Error, message, ex); } }