protected override void ProcessImage(object sender) { try { int rGMin = int.Parse(this.RGMin); int rGMax = int.Parse(this.RGMax); int gGMin = int.Parse(this.GGMin); int gGMax = int.Parse(this.GGMax); int bGMin = int.Parse(this.BGMin); int bGMax = int.Parse(this.BGMax); if (rGMin < 0 || rGMin > 255 || rGMax < 0 || rGMax > 255 || rGMin > rGMax || gGMin < 0 || gGMin > 255 || gGMax < 0 || gGMax > 255 || gGMin > gGMax || bGMin < 0 || bGMin > 255 || bGMax < 0 || bGMax > 255 || bGMin > bGMax) { throw new ArgumentException("Invalid input range!"); } Bitmap input = this.WorkspaceViewModel.Input; Bitmap output = this.WorkspaceViewModel.GetClonedInput(); BarchartData barchartData = BarchartData.GenerateBarcharData(256, input); int n = input.Width * input.Height; for (int i = 0; i < output.Width; i++) { for (int j = 0; j < output.Height; j++) { Color pixel = input.GetPixel(i, j); output.SetPixel(i, j, Color.FromArgb( this.CalculateNewPixelValue(rGMin, rGMax, i, j, pixel.R, barchartData.Red, n), this.CalculateNewPixelValue(gGMin, gGMax, i, j, pixel.G, barchartData.Green, n), this.CalculateNewPixelValue(bGMin, bGMax, i, j, pixel.B, barchartData.Blue, n) )); } } this.WorkspaceViewModel.Output = output; } catch (Exception) { Notify.Error("Invalid input value!\nGmin must be an int between 0 and 255.\nGmax must be an int between 0 and 255.\nGmin must be lower than Gmax."); } }
public ContentResult GetTotalExpenseByTypeMonthly(GetServiceInput input) { try { ChartJsHelper chartJsHelper = new ChartJsHelper(); chartJsHelper.barChartData = new List <BarchartData>(); List <string> barchartlabels = new List <string>(); List <float> bardata = new List <float>(); for (int i = 1; i <= 12; i++) { string month = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(i); barchartlabels.Add(month.ToString()); bardata.Add(0); } chartJsHelper.barChartLabels = barchartlabels.ToArray(); var data = _unitOfWork.ServiceHistory.GetTotalExpenseByTypeMonthly(); foreach (var item in data) { if (chartJsHelper.barChartData.Where(x => x.label == Utility.getservicetypename(item.ServicingType)).Count() == 0) { BarchartData barchartdata = new BarchartData(); BarchartData barchartdata1 = new BarchartData(); barchartdata.data = new List <float>(); List <float> bardata1 = new List <float>(bardata); bardata1[item.Month - 1] = ((float)item.Amount); //barchartdata.data.Add ((float)item.Amount); barchartdata.label = Utility.getservicetypename(item.ServicingType); barchartdata.data = bardata1; chartJsHelper.barChartData.Add(barchartdata); } else { foreach (var item1 in chartJsHelper.barChartData) { if (Utility.getservicetypename(item.ServicingType) == item1.label) { item1.data[item.Month - 1] = ((float)item.Amount); } } } } chartJsHelper.barChartLegend = true; if (chartJsHelper.barChartData.Count() == 0) { BarchartData barchartdata = new BarchartData(); barchartdata.data = new List <float>(); for (int i = 0; i < 12; i++) { barchartdata.data.Add((float)0); } barchartdata.label = ""; //barchartdata.data.Add ((float)item.Amount); chartJsHelper.barChartData.Add(barchartdata); } chartJsHelper.barChartType = "bar"; return(this.Content(JsonConvert.SerializeObject(chartJsHelper), "application/json")); } catch (Exception ex) { return(this.Content(JsonConvert.SerializeObject(new { msgCode = -3, msg = ex.Message }), "application/json")); } }
protected override void ProcessImage(object sender) { try { int n = int.Parse(this.N); if (n > 255 || n < 1) { throw new ArgumentException("Invalid input range!"); } List <string> Labels = new List <string>(); Bitmap input = this.WorkspaceViewModel.Input; double range = 255.0 / n; double start = 0; for (int i = 0; i < n; i++) { if (i != n - 1) { double next = start + range; Labels.Add(Convert.ToInt32(start) + "-" + Convert.ToInt32(next)); start = next; } else { Labels.Add(Convert.ToInt32(start) + "-" + 255); } } BarchartData barchartData = BarchartData.GenerateBarcharData(n, input); Task.Run(() => { Application.Current.Dispatcher.Invoke(delegate { SeriesCollection red = new SeriesCollection(); red.Add(new LineSeries { Title = "R", Values = new ChartValues <int>(barchartData.Red), Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 0, 0)), PointGeometry = null }); SeriesCollection green = new SeriesCollection(); green.Add(new LineSeries { Title = "G", Values = new ChartValues <int>(barchartData.Green), Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 255, 0)), PointGeometry = null }); SeriesCollection blue = new SeriesCollection(); blue.Add(new LineSeries { Title = "B", Values = new ChartValues <int>(barchartData.Blue), Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 255)), PointGeometry = null }); Window redWindow = new BarchartView(red, Labels); Window greenWindow = new BarchartView(green, Labels); Window blueWindow = new BarchartView(blue, Labels); redWindow.Show(); greenWindow.Show(); blueWindow.Show(); }); }); } catch (Exception) { Notify.Error("Invalid input value!\nValue must be an int between 1 and 256."); } }