public static Bitmap ToBitmap(this double[,] array, ColormapBrush ColorMap) { int width = array.GetLength(1); int height = array.GetLength(0); System.Drawing.Bitmap Image = new System.Drawing.Bitmap(width, height); System.Drawing.Imaging.BitmapData bitmapData = Image.LockBits( new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); //Iterating over height for (int j = 0; j < height; j++) { //Iterating over width for (int k = 0; k < width; k++) { try { System.Windows.Media.Brush br = ColorMapHelper.GetBrush((double)array[j, k], ColorMap.Ymin, ColorMap.Ymax, ColorMap); byte a = ((Color)br.GetValue(System.Windows.Media.SolidColorBrush.ColorProperty)).A; byte g = ((Color)br.GetValue(System.Windows.Media.SolidColorBrush.ColorProperty)).G; byte r = ((Color)br.GetValue(System.Windows.Media.SolidColorBrush.ColorProperty)).R; byte b = ((Color)br.GetValue(System.Windows.Media.SolidColorBrush.ColorProperty)).B; Image.SetPixel(k, j, System.Drawing.Color.FromArgb(a, r, g, b)); } catch { continue; } } } return(Image); }
/// <summary> /// Add a 3D line to a chart canvas /// </summary> /// <param name="cs"></param> public async Task <List <UIElement> > AddLine3D(LineSeries3D ls, ColormapBrush cm, CancellationToken token) { List <UIElement> symbols = new List <UIElement>(); await Application.Current.Dispatcher.InvokeAsync(async() => { var pLine = new Polyline(); Matrix3D m = Chart3DHelper.AzimuthElevation(Elevation, Azimuth); Point3D[] pts = new Point3D[ls.LinePoints.Count]; int stepWidth = 1; if (ls.LinePoints.Count > 20000) { stepWidth = (ls.LinePoints.Count / 20000); } for (int i = 0; i < ls.LinePoints.Count; i += stepWidth) { if (token.IsCancellationRequested) { break; } if (i == 0) { Console.WriteLine("1:" + DateTime.Now); } await Task.Delay(1); if (ls.LinePoints[i].Item1.X <Xmin || ls.LinePoints[i].Item1.X> Xmax || ls.LinePoints[i].Item1.Y <Ymin || ls.LinePoints[i].Item1.Y> Ymax || ls.LinePoints[i].Item1.Z <Zmin || ls.LinePoints[i].Item1.Z> Zmax) { continue; } try { if (i == 0) { Console.WriteLine("2:" + DateTime.Now); } pts[i] = Normalize3D(m, ls.LinePoints[i].Item1); pLine.Points.Add(new Point(pts[i].X, pts[i].Y)); if (i == 0) { Console.WriteLine("3:" + DateTime.Now); } if (!IsBubbleChart) { if (ls.Symbols.SymbolType != SymbolTypeEnum.None) { ls.Symbols.AddSymbol(ChartCanvas, new Point(pts[i].X, pts[i].Y)); } } else if (ls.Symbols.SymbolType != SymbolTypeEnum.None) { ls.Symbols.FillColor = ColorMapHelper.GetBrush(ls.LinePoints[i].Item2, cm.Ymin, cm.Ymax, cm); symbols.AddRange(ls.Symbols.GetSymbol(new Point(pts[i].X, pts[i].Y))); } } catch { continue; } if (i == 0) { Console.WriteLine("4:" + DateTime.Now); } } if (!IsBubbleChart) { SetLinePattern(ls, pLine); symbols.Add(pLine); } }).Result; return(symbols); }