예제 #1
0
        /// <summary>
        /// Exports the specified plot model to an xps file.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="fileName">The file name.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background color.</param>
        public static void Export(IPlotModel model, string fileName, double width, double height, OxyColor background)
        {
            using (var xpsPackage = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite))
            {
                using (var doc = new XpsDocument(xpsPackage))
                {
                    var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() };
                    canvas.Measure(new Size(width, height));
                    canvas.Arrange(new Rect(0, 0, width, height));

                    var rc = new ShapesRenderContext(canvas);
#if !NET35
                    rc.TextFormattingMode = TextFormattingMode.Ideal;
#endif

                    model.Update(true);
                    model.Render(rc, width, height);

                    canvas.UpdateLayout();

                    var xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
                    xpsdw.Write(canvas);
                }
            }
        }
예제 #2
0
        public static RenderTargetBitmap SaveCanvasToBitmap(Canvas canvas)
        {
            // Save current canvas transform
            Transform transform = canvas.LayoutTransform;
            // reset current transform (in case it is scaled or rotated)
            canvas.LayoutTransform = null;

            // Get the size of canvas
            Size size = new Size(canvas.Width, canvas.Height);
            // Measure and arrange the surface
            // VERY IMPORTANT
            canvas.Measure(size);
            canvas.Arrange(new Rect(size));

            // Create a render bitmap and push the surface to it
            RenderTargetBitmap renderBitmap =
              new RenderTargetBitmap(
                (int)size.Width,
                (int)size.Height,
                96d,
                96d,
                PixelFormats.Pbgra32);
            renderBitmap.Render(canvas);

            return renderBitmap;
        }
 protected override void RenderSample()
 {
     var canvas = new Canvas { Width = 10, Height = 10, SnapsToDevicePixels = true, Background = Brushes.Transparent };
     canvas.Children.Add(new Path
     {
         Stroke = Stroke,
         StrokeThickness = StrokeThickness,
         Fill = Fill,
         Data = new RectangleGeometry(new Rect(0, 0, 10, 10)),
     });
     canvas.Measure(new Size(canvas.Width, canvas.Height));
     canvas.Arrange(new Rect(0, 0, canvas.Width, canvas.Height));
     var dpiX = 96.0;
     var dpiY = 96.0;
     var source = PresentationSource.FromVisual(Application.Current.MainWindow);
     if (source != null && source.CompositionTarget != null)
     {
         var matrix = source.CompositionTarget.TransformToDevice;
         dpiX *= matrix.M11;
         dpiY *= matrix.M22;
     }
     var rtb = new RenderTargetBitmap((int)Math.Round(canvas.Width), (int)Math.Round(canvas.Height), dpiX, dpiY, PixelFormats.Pbgra32);
     rtb.Render(canvas);
     SampleImageSource = rtb;
 }
        public static bool[,] Rasterize(Point[] points, int width, int height)
        {
            Contract.Requires(points != null);
            Contract.Requires(width > 0);
            Contract.Requires(height > 0);
            Contract.Requires(width % 8 == 0);
            Contract.Ensures(Contract.Result<bool[,]>() != null);
            Contract.Ensures(Contract.Result<bool[,]>().GetLength(0) == width);
            Contract.Ensures(Contract.Result<bool[,]>().GetLength(1) == height);

            var canvas = new Canvas { Background = Brushes.White, Width = width, Height = height };
            var polygon = new Polygon { Stroke = Brushes.Black, Fill = Brushes.Black, StrokeThickness = 1, Points = new PointCollection(points) };
            canvas.Children.Add(polygon);
            RenderOptions.SetEdgeMode(canvas, EdgeMode.Aliased);

            canvas.Measure(new Size(width, height));
            canvas.Arrange(new Rect(0, 0, canvas.DesiredSize.Width, canvas.DesiredSize.Height));

            var rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);
            rtb.Render(canvas);

            var fmb = new FormatConvertedBitmap(rtb, PixelFormats.BlackWhite, null, 0);
            var pixels = new byte[width * height / 8];
            fmb.CopyPixels(pixels, width / 8, 0);

            System.Collections.BitArray ba = new System.Collections.BitArray(pixels);

            var result = new bool[width, height];
            for (int i = 0, y = 0; y < height; ++y)
                for (int x = 0; x < width; ++x, ++i)
                    result[x, y] = !ba[i];

            return result;
        }
        public void SaveToPng( Canvas surface, string file )
        {
            // Save current canvas transform
            var transform = surface.LayoutTransform;
            // reset current transform (in case it is scaled or rotated)
            surface.LayoutTransform = null;

            var size = new Size( 1600, 900 );

            // Attentation: Measure and arrange the surface !
            surface.Measure( size );
            surface.Arrange( new Rect( size ) );

            var renderBitmap = new RenderTargetBitmap( (int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Pbgra32 );

            var bounds = VisualTreeHelper.GetDescendantBounds( surface );
            var dv = new DrawingVisual();
            using ( var ctx = dv.RenderOpen() )
            {
                var vb = new VisualBrush( surface );
                ctx.DrawRectangle( vb, null, new Rect( new Point(), bounds.Size ) );
            }

            renderBitmap.Render( dv );
            using ( var outStream = new FileStream( file, FileMode.OpenOrCreate, FileAccess.Write ) )
            {
                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add( BitmapFrame.Create( renderBitmap ) );
                encoder.Save( outStream );
            }

            // Restore previously saved layout
            surface.LayoutTransform = transform;
        }
예제 #6
0
      void loader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
         buff.UpdateLayout();

         Canvas canvas = new Canvas();
         canvas.Children.Add(buff);
         canvas.Width = 512 * 13;
         canvas.Height = 512 * 7;

         canvas.UpdateLayout();

         canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height));
         canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height)));
         int Height = ((int)(canvas.ActualHeight));
         int Width = ((int)(canvas.ActualWidth));

         RenderTargetBitmap _RenderTargetBitmap = new RenderTargetBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32);
         _RenderTargetBitmap.Render(buff);

         Image img = new Image();
         img.Source = _RenderTargetBitmap;

         Viewer.PanoramaImage = _RenderTargetBitmap;

         Title = "Demo.StreetView, enjoy! ;}";
      }
예제 #7
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ChildlessMeasureTest ()
		{
			Canvas c = new Canvas ();
			Size s = new Size (10,10);

			c.Measure (s);

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "DesiredSize");
		}
 public static void Store(IEnumerable<Point> points, int width, int height, string fileName)
 {
     var canvas = new Canvas { Background = Brushes.White };
     canvas.Width = width;
     canvas.Height = height;
     canvas.Children.Add(new Polyline { Stroke = Brushes.Black, StrokeThickness = 1, Points = new PointCollection(points) });
     canvas.Measure(new Size(width, height));
     canvas.Arrange(new Rect(0, 0, canvas.DesiredSize.Width, canvas.DesiredSize.Height));
     RenderOptions.SetEdgeMode(canvas, EdgeMode.Aliased);
     Store(canvas, fileName);
 }
 protected override void RenderSample()
 {
     StreamGeometry geometry;
     var canvas = new Canvas { Width = Math.Max(MarkerSize + 10, 10), Height = Math.Max(MarkerSize + 2, 10), SnapsToDevicePixels = true, Background = Brushes.Transparent };
     if (DrawLine)
     {
         geometry = new StreamGeometry();
         using (var ctx = geometry.Open())
         {
             ctx.BeginFigure(new Point(0, canvas.Height / 2), false, false);
             ctx.LineTo(new Point(canvas.Width, canvas.Height / 2), true, false);
         }
         canvas.Children.Add(new Path
         {
             Stroke = LineStroke,
             StrokeThickness = LineStrokeThickness,
             StrokeDashArray = LineStrokeDashArray,
             Data = geometry,
         });
     }
     if (DrawMarker)
     {
         geometry = new StreamGeometry();
         using (var ctx = geometry.Open())
         {
             MarkerType(ctx, new Point(canvas.Width / 2, canvas.Height / 2), MarkerSize);
         }
         canvas.Children.Add(new Path
         {
             Stroke = MarkerStroke,
             StrokeThickness = MarkerStrokeThickness,
             Data = geometry,
         });
     }
     canvas.Measure(new Size(canvas.Width, canvas.Height));
     canvas.Arrange(new Rect(0, 0, canvas.Width, canvas.Height));
     var dpiX = 96.0;
     var dpiY = 96.0;
     var source = PresentationSource.FromVisual(Application.Current.MainWindow);
     if (source != null && source.CompositionTarget != null)
     {
         var matrix = source.CompositionTarget.TransformToDevice;
         dpiX *= matrix.M11;
         dpiY *= matrix.M22;
     } 
     var rtb = new RenderTargetBitmap((int)Math.Round(canvas.Width), (int)Math.Round(canvas.Height), dpiX, dpiY, PixelFormats.Pbgra32);
     rtb.Render(canvas);
     SampleImageSource = rtb;
 }
예제 #10
0
        protected void CreateIcon(Floor floor)
        {
            ItemsControl control = new ItemsControl();
            Canvas canvas = new Canvas();
            control.ItemTemplate = Application.Current.FindResource("SegmentRowTemplate") as DataTemplate;
            canvas.Children.Add(control);

            control.ItemsSource = floor.Segments;
            control.UpdateLayout();
            canvas.Measure(new Size(1000, 1000));
            canvas.Arrange(new Rect(new Size(1000, 1000)));

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)control.DesiredSize.Width, (int)control.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(control);

            floor.Icon = bmp;
        }
예제 #11
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ChildMeasureTest2 ()
		{
			Canvas c = new Canvas ();
			Rectangle r = new Rectangle();

			c.Children.Add (r);

			Canvas.SetLeft (r, 10);
			Canvas.SetTop (r, 10);

			r.Width = 50;
			r.Height = 50;

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (0,0), c.DesiredSize);
		}
예제 #12
0
        public void SaveFile(Canvas canvas, string filename)
        {
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)canvas.Width, (int)canvas.Height, 96d, 96d, PixelFormats.Pbgra32);
            // needed otherwise the image output is black
            canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height));
            canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height)));

            renderBitmap.Render(canvas);

            //JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(renderBitmap));

            using (FileStream file = File.Create(filename))
            {
                encoder.Save(file);
            }
        }
예제 #13
0
        /// <summary>
        /// Renders a UI control into an image.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="isWideTile"></param>
        /// <returns></returns>
        public static void CreateImage(UIElement control, string imagePath, int width, int height, SolidColorBrush tileBackgroundColor)
        {
            // 1. Setup dimensions for wide tile.
            var bmp = new WriteableBitmap(width, height);

            // 2. Get the name of the background image based on theme            
            var canvas = new System.Windows.Controls.Canvas();
            canvas.Width = width;
            canvas.Height = height;
            canvas.Background = tileBackgroundColor;

            canvas.Children.Add(control);
            canvas.Measure(new Size(width, height));
            canvas.Arrange(new Rect(0, 0, width, height));
            canvas.UpdateLayout();

            // 4. Now output the control as text.
            bmp.Render(canvas, null);
            bmp.Invalidate();

            // 8. Now save the image to local folder.
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // FileMode.Open, FileAccess.Read, FileShare.Read,
                using (var st = new IsolatedStorageFileStream(imagePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, store))
                {
                    bmp.SaveJpeg(st, width, height, 0, 100);
                    st.Close();
                }
            }

            try
            {

                bmp = null;
                canvas.Children.Clear();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception ex)
            {
                Slate.Core.Logging.Logger.Error("Create image", "Warning, attempt to clear up memory for tile image failed", ex);
            }
        }
예제 #14
0
        /// <summary>
        /// Exports the specified plot model to a stream.
        /// </summary>
        /// <param name="model">The plot model.</param>
        /// <param name="stream">The stream to write to.</param>
        /// <param name="width">The width of the export image.</param>
        /// <param name="height">The height of the exported image.</param>
        /// <param name="background">The background.</param>
        public static void Export(IPlotModel model, Stream stream, double width, double height, OxyColor background)
        {
            var canvas = new Canvas { Width = width, Height = height };
            if (background.IsVisible())
            {
                canvas.Background = background.ToBrush();
            }

            canvas.Measure(new Size(width, height));
            canvas.Arrange(new Rect(0, 0, width, height));

            var rc = new SilverlightRenderContext(canvas);
            model.Update(true);
            model.Render(rc, width, height);

            canvas.UpdateLayout();
            var image = canvas.ToImage();
            image.WriteToStream(stream);
        }
예제 #15
0
파일: RectangleTest.cs 프로젝트: dfr0/moon
		public void MeasureTest2 ()
		{
			Canvas c = new Canvas ();
			Rectangle r = new Rectangle ();
			r.Width = 10;
			r.Height = 20;

			r.Measure (new Size (50, 50));
			Assert.AreEqual (new Size (0, 0), r.DesiredSize);
			
			c.Children.Add (r);

			r.Measure (new Size (50, 50));
			Assert.AreEqual (new Size (0, 0), r.DesiredSize);

			c.Measure (new Size (50, 50));

			Assert.AreEqual (new Size (0, 0), c.DesiredSize, "Canvas desired");
			Assert.AreEqual (new Size (0, 0), r.DesiredSize, "Rectangle desired");
		}
예제 #16
0
        public BitmapImage canvastoBitmap(Canvas canvas)
        {
            Size size = new Size(canvas.ActualWidth, canvas.ActualHeight);
            canvas.Measure(size);
            canvas.Arrange(new Rect(size));

            RenderTargetBitmap bitmap = new RenderTargetBitmap((int)canvas.ActualWidth, (int)canvas.ActualHeight, 96d, 96d, PixelFormats.Pbgra32);
            bitmap.Render(canvas);
            BitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bitmap));

            BitmapImage bmp = new BitmapImage() { CacheOption = BitmapCacheOption.OnLoad };
            MemoryStream outStream = new MemoryStream();
            encoder.Save(outStream);
            outStream.Seek(0, SeekOrigin.Begin);
            bmp.BeginInit();
            bmp.StreamSource = outStream;
            bmp.EndInit();
            return bmp;
        }
예제 #17
0
        public static RenderTargetBitmap ToBitmap(this System.Windows.Controls.Canvas canvas)
        {
            Size size = new Size(canvas.ActualWidth, canvas.ActualHeight);

            canvas.Measure(size);
            canvas.Arrange(new Rect(size));

            // Create a render bitmap and push the surface to it
            RenderTargetBitmap renderBitmap =
                new RenderTargetBitmap(
                    (int)size.Width,
                    (int)size.Height,
                    96d,
                    96d,
                    PixelFormats.Pbgra32);

            renderBitmap.Render(canvas);

            return(renderBitmap);
        }
예제 #18
0
		/// <summary>
		///     Преобразует Xaml-canvas в png изображение
		/// </summary>
		/// <param name="surface">XAML Canvas</param>
		/// <returns>Bitmap, rendered from XAML</returns>
		public static Bitmap XamlCanvasToPngBitmap(Canvas surface) {
			if (surface == null) {
				throw new ArgumentNullException("surface");
			}

			// Save current canvas transform
			var transform = surface.LayoutTransform;
			// reset current transform (in case it is scaled or rotated)
			surface.LayoutTransform = null;

			// Get the size of canvas
			var size = new System.Windows.Size(surface.Width, surface.Height);
			// Measure and arrange the surface
			// VERY IMPORTANT
			surface.Measure(size);
			surface.Arrange(new Rect(size));

			// Create a render bitmap and push the surface to it
			var renderBitmap =
				new RenderTargetBitmap(
					(int)size.Width,
					(int)size.Height,
					96d,
					96d,
					PixelFormats.Pbgra32);
			renderBitmap.Render(surface);

			Bitmap bmp;
			// Create a file stream for saving image
			using (var stream = new MemoryStream()) {
				// Use png encoder for our data
				var encoder = new PngBitmapEncoder();
				// push the rendered bitmap to it
				encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
				// save the data to the stream
				encoder.Save(stream);

				bmp = new Bitmap(stream);
			}
			return bmp;
		}
        public void ExportToPng(Uri path, Canvas surface)
        {
            if (path == null)
                return;

            // Save current canvas transform
            Transform transform = surface.LayoutTransform;
            // reset current transform (in case it is scaled or rotated)
            surface.LayoutTransform = null;

            // Get the size of canvas
            System.Windows.Size size = new System.Windows.Size(surface.Width, surface.Height);
            // Measure and arrange the surface
            // VERY IMPORTANT
            surface.Measure(size);
            surface.Arrange(new Rect(size));

            // Create a render bitmap and push the surface to it
            RenderTargetBitmap renderBitmap =
              new RenderTargetBitmap(
                (int)size.Width,
                (int)size.Height,
                96d,
                96d,
                PixelFormats.Pbgra32);
            renderBitmap.Render(surface);

            // Create a file stream for saving image
            using (FileStream outStream = new FileStream(path.LocalPath, FileMode.Create))
            {
                // Use png encoder for our data
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                // push the rendered bitmap to it
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                // save the data to the stream
                encoder.Save(outStream);
            }

            // Restore previously saved layout
            surface.LayoutTransform = transform;
        }
예제 #20
0
        public void CanvasLayoutTest()
        {
            Canvas panel = new Canvas();

            FrameworkElement child1 = new FrameworkElement { Width = 200, Height = 100 };
            FrameworkElement child2 = new FrameworkElement { Width = 200, Height = 100 };
            FrameworkElement child3 = new FrameworkElement { Width = 200, Height = 100 };
            FrameworkElement child4 = new FrameworkElement { Width = 200, Height = 100 };

            Canvas.SetLeft(child1, 20);
            Canvas.SetTop(child1, 10);
            Canvas.SetRight(child2, 20);
            Canvas.SetTop(child2, 10);
            Canvas.SetRight(child3, 20);
            Canvas.SetBottom(child3, 10);
            Canvas.SetLeft(child4, 20);
            Canvas.SetBottom(child4, 10);

            panel.Children.Add(child1);
            panel.Children.Add(child2);
            panel.Children.Add(child3);
            panel.Children.Add(child4);

            panel.Measure(new Size(1000, 1000));

            Assert.AreEqual(Size.Zero, panel.DesiredSize);

            panel.Arrange(new Rect(1000, 1000));

            Assert.AreEqual(new Size(1000, 1000), panel.VisualSize);

            Assert.AreEqual(new Size(200, 100), child1.VisualSize);
            Assert.AreEqual(new Size(200, 100), child2.VisualSize);
            Assert.AreEqual(new Size(200, 100), child3.VisualSize);
            Assert.AreEqual(new Size(200, 100), child4.VisualSize);

            Assert.AreEqual(new Point(20, 10), child1.VisualOffset);
            Assert.AreEqual(new Point(780, 10), child2.VisualOffset);
            Assert.AreEqual(new Point(780, 890), child3.VisualOffset);
            Assert.AreEqual(new Point(20, 890), child4.VisualOffset);
        }
예제 #21
0
        /// <summary>
        /// Exports the specified plot model to a xml writer.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="writer">The xml writer.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background.</param>
        private static void Export(IPlotModel model, XmlWriter writer, double width, double height, OxyColor background)
        {
            var c = new Canvas();
            if (background.IsVisible())
            {
                c.Background = background.ToBrush();
            }

            c.Measure(new Size(width, height));
            c.Arrange(new Rect(0, 0, width, height));

            var rc = new CanvasRenderContext(c) { UseStreamGeometry = false };

            rc.TextFormattingMode = TextFormattingMode.Ideal;

            model.Update(true);
            model.Render(rc, width, height);

            c.UpdateLayout();

            XamlWriter.Save(c, writer);
        }
예제 #22
0
        private void Test_Click(object sender, RoutedEventArgs e)
        {
            Canvas c = new Canvas();
            ItemsControl control = new ItemsControl();
            var template = uxDataFloor.ItemTemplate;
            control.ItemTemplate = Application.Current.FindResource("SegmentRowTemplate") as DataTemplate;
            control.ItemsSource = _viewModel.CurrentBuilding.Floors[0].Segments;
            c.Children.Add(control);

            c.Measure(new Size(1000, 1000));
            c.Arrange(new Rect(new Size(1000, 1000)));

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)control.DesiredSize.Width, (int)control.DesiredSize.Height, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(control);

            var encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bmp));
            using (Stream stm = File.Create(@"D:\test.png"))
            {
                encoder.Save(stm);
            }
            return;

            //int width = (int)uxDataFloor.ActualWidth;
            //int height = (int)uxDataFloor.ActualHeight;
            //int width = 1000;
            //int height = 1000;

            //uxDataFloor.Measure(new Size(width, height));
            //uxDataFloor.Arrange(new Rect(uxDataFloor.DesiredSize));

            //RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
            //bmp.Render(uxDataFloor);

            //var encoder = new PngBitmapEncoder();
            //encoder.Frames.Add(BitmapFrame.Create(bmp));
            //using (Stream stm = File.Create(@"D:\test.png"))
            //{
            //    encoder.Save(stm);
            //}
        }
예제 #23
0
        private void btSaveImage_Click(object sender, RoutedEventArgs e) {

            if (_collector == null)
                return;

            // Create new canvas and renderer
            var cnv = new Canvas() { Margin = cnvChart.Margin, Width = cnvChart.ActualWidth, Height = cnvChart.ActualHeight, Background = System.Windows.Media.Brushes.White };            
            var ch = new ChartRendering.ChartRenderer(cnv, _collector.Datas);
            cnv.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
            cnv.Arrange(new Rect(0, 0, cnv.DesiredSize.Width, cnv.DesiredSize.Height));
            var cwidth = (int)cnv.RenderSize.Width;
            var cheight = (int)(cnv.RenderSize.Height + cnv.Margin.Top * 2);
            var rtb = new RenderTargetBitmap(cwidth, cheight, 96d, 96d, PixelFormats.Default);

            // Generate a white background
            var dv = new DrawingVisual();
            var dvct = dv.RenderOpen();
            dvct.DrawRectangle(System.Windows.Media.Brushes.White, null, new Rect(0, 0, rtb.Width, rtb.Height));
            dvct.Close();
            rtb.Render(dv);

            // Render chart and create Bitmap
            ch.Render(false);
            // Add additional informations overlays            
            AddChartImageInfos(cnv);
            cnv.UpdateLayout();
            rtb.Render(cnv);

            // Open file dialog and save image if OK
            var fd = new SaveFileDialog();
            fd.Filter = "PNG Images|*.png";
            fd.DefaultExt = ".png";
            fd.InitialDirectory = Properties.Settings.Default.fdpath_img;

            if (true == fd.ShowDialog(this)) {
                Properties.Settings.Default.fdpath_img = Path.GetDirectoryName(fd.FileName);
                Properties.Settings.Default.Save();

                var bf = BitmapFrame.Create(rtb);
                var pngEncoder = new PngBitmapEncoder();
                pngEncoder.Frames.Add(bf);                
                using (var st = System.IO.File.OpenWrite(fd.FileName)) {
                    pngEncoder.Save(st);
                }

                var result = MessageBox.Show("Show generated file in Explorer ?", "Image successfully generated", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                    System.Diagnostics.Process.Start("explorer.exe", "/select, " + fd.FileName);
            }
            
        }
예제 #24
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ChildMeasureTest4 ()
		{
			Border root = new Border ();
			Canvas c = new Canvas ();
			Border r = new Border ();

			root.Child = c;
			c.Children.Add (r);

			Canvas.SetLeft (r, 10);
			Canvas.SetTop (r, 10);

			r.Width = 50;
			r.Height = 50;

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (0,0), c.DesiredSize);
			Assert.AreEqual (new Size (50,50), r.DesiredSize);
		}
예제 #25
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ChildMeasureTest3 ()
		{
			Canvas c = new Canvas ();
			Border r = new Border ();

			c.Children.Add (r);

			Canvas.SetLeft (r, 10);
			Canvas.SetTop (r, 10);

			r.Width = 50;
			r.Height = 50;

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c deisred");
			Assert.AreEqual (new Size (0,0), r.DesiredSize, "r desired");
			Assert.AreEqual (new Size (0,0), new Size (r.ActualWidth, r.ActualHeight));
		}
예제 #26
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void AttachedTest ()
		{
			Canvas c = new Canvas ();
			Border b = new Border ();
			b.Width = 10;
			b.Height = 33;
			b.Background = new SolidColorBrush (Colors.Orange);
			Canvas.SetTop (b, 88);
			Canvas.SetLeft (b, 150);
			c.Children.Add (b);

			c.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired");

			c.Arrange (new Rect (0,0,400,400));
			
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (b));
		}
예제 #27
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void WidthHeightBackgroundMeasureTest2 ()
		{
			Canvas c = new Canvas ();

			c.Background = new SolidColorBrush (Colors.Black);

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");

			c.Width = 50;
			c.Height = 60;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (50,60), new Size (c.ActualWidth,c.ActualHeight), "c actual1");

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (50,60), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
		}
예제 #28
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ComputeActualWidthCanvas ()
		{
			Canvas b = new Canvas ();
			Canvas c = new Canvas ();

			b.Children.Add (c);

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");

			c.MaxWidth = 25;
			c.Width = 50;
			c.MinHeight = 33;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (25,33), new Size (c.ActualWidth,c.ActualHeight), "c actual1");

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (25,33), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
		}
예제 #29
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ComputeActualWidthGrid ()
		{
			Grid b = new Grid ();
			Canvas c = new Canvas ();

			b.Children.Add (c);

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired1");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot");

			c.MaxWidth = 25;
			c.Width = 50;
			c.MinHeight = 33;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired2");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual2");

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (25,33), c.DesiredSize, "c desired3");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual3");
		}
예제 #30
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ComputeActualWidthBorder ()
		{
			Border b = new Border ();
			Canvas c = new Canvas ();

			b.Child = c;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired1");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot");

			c.MaxWidth = 25;
			c.Width = 50;
			c.MinHeight = 33;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired2");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot");

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (25,33), c.DesiredSize, "c desired3");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual3");

			Assert.IsTrue (c.UseLayoutRounding, "use rounding");
		}
예제 #31
0
파일: CanvasTest.cs 프로젝트: kangaroo/moon
		public void ComputeActualWidth ()
		{
			Canvas c = new Canvas ();

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");

			c.MaxWidth = 25;
			c.Width = 50;
			c.MinHeight = 33;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (25,33), new Size (c.ActualWidth,c.ActualHeight), "c actual1");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot");

			c.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (25,33), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
			Assert.AreEqual (new Size (0,0), c.RenderSize, "c render");

			c.Arrange (new Rect (0,0,c.DesiredSize.Width,c.DesiredSize.Height));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (25,33), new Size (c.ActualWidth,c.ActualHeight), "c actual3");
			Assert.AreEqual (new Size (0,0), c.RenderSize, "c render");
		}