Hi, how can I get screenshot of sparkline?
I do the following:
RadSparklineBase sparkline = new RadLinearSparkline();sparkline.XValuePath = "X";sparkline.YValuePath = "Y";sparkline.Margin = new Thickness(0);sparkline.Width = width;sparkline.Height = height;sparkline.ItemsSource = new SparkPoint[]{new SparkPoint(10, 10),new SparkPoint(10, 20),new SparkPoint(20, 10),new SparkPoint(10, 5)};DrawingVisual visual = new DrawingVisual();using (visual.RenderOpen()){new VisualBrush sparkline);}using (MemoryStream stream = new MemoryStream()){Rect rect = new Rect(0, 0, (int)width, (int)height);RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32);sparkline.Arrange(rect);renderTargetBitmap.Render(sparkline);PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();pngBitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));pngBitmapEncoder.Save(stream);stream.Flush();image = Image.FromStream(stream);}
Is it possible to make it work? Thanks.
I do the following:
RadSparklineBase sparkline = new RadLinearSparkline();sparkline.XValuePath = "X";sparkline.YValuePath = "Y";sparkline.Margin = new Thickness(0);sparkline.Width = width;sparkline.Height = height;sparkline.ItemsSource = new SparkPoint[]{new SparkPoint(10, 10),new SparkPoint(10, 20),new SparkPoint(20, 10),new SparkPoint(10, 5)};DrawingVisual visual = new DrawingVisual();using (visual.RenderOpen()){new VisualBrush sparkline);}using (MemoryStream stream = new MemoryStream()){Rect rect = new Rect(0, 0, (int)width, (int)height);RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32);sparkline.Arrange(rect);renderTargetBitmap.Render(sparkline);PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();pngBitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));pngBitmapEncoder.Save(stream);stream.Flush();image = Image.FromStream(stream);}
Is it possible to make it work? Thanks.