private void Create3DViewPort()
        {
            var hvp3d = new HelixViewport3D();
            Viewport3D vp3d = new Viewport3D();
            var lights = new DefaultLights();
            var tp = new Teapot();

            hvp3d.Children.Add(lights);
            hvp3d.Children.Add(tp);

            vp3d = hvp3d.Viewport;
            tata.Children.Add(vp3d); // comenter ca pour test

            /* MEGA TEST DE L'ESPACE SUBSAHARIEN */

            RenderTargetBitmap bmp = new RenderTargetBitmap(800, 800, 96, 96, PixelFormats.Pbgra32);
            var rect = new Rect(0, 0, 800, 800);
            vp3d.Measure(new Size(800, 800));
            vp3d.Arrange(rect);
            vp3d.InvalidateVisual();
            
            bmp.Render(vp3d);

            PngBitmapEncoder png = new PngBitmapEncoder();
            png.Frames.Add(BitmapFrame.Create(bmp));

            String filepath = "C:\\Users\\Remi\\Desktop\\canardmasque.png";
            using (Stream stm = File.Create(filepath))
            {
                png.Save(stm);
            }
        }
        public void copyFaceImage(Viewport3D viewport3d)
        {

            if (renderEnabled)
                renderEnabled = false;
            else
                return;

            int width = 300;
            int height = 300;

            viewport3d.Width = width;

            viewport3d.Height = height;

            viewport3d.Measure(new Size(width, height));

            viewport3d.Arrange(new System.Windows.Rect(0, 0, width, height));

            //            bmp = new RenderTargetBitmap((int)viewport3d.ActualWidth, (int)viewport3d.ActualHeight, 96, 96, PixelFormats.Pbgra32);
            //            bmp.Render(viewport3d);

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)viewport3d.ActualWidth,
                (int)viewport3d.ActualHeight, 96, 96, PixelFormats.Default);
            bmp.Render(viewport3d);
            //FaceImage.imageObj = bmp;
            //            viewport3d.Visibility = Visibility.Collapsed;
            //            FaceImage.Visibility = Visibility.Visible;

            faceGrid[currentMatrixRow, currentMatrixColumn].ImageObj.Source = bmp;
            faceGrid[currentMatrixRow, currentMatrixColumn].ImageObj.Visibility = Visibility.Visible;

            if (currentMatrixRow < 3) currentMatrixRow++;
            else
            {
                currentMatrixRow = 0;
                if (currentMatrixColumn < 3) currentMatrixColumn++;
                else
                    currentMatrixColumn = 0;
            }


            //this.saveFaceImageToFile(bmp);
            //taskFactory.StartNew(() => saveFaceImageToFile(bmp));
        }
Exemple #3
0
        public void Convert_to_Image(Canvas can, int pane_number)
        {

            if (pane_number == -1)
            {

                //clear hashtable as new plot will overwirte previous image
                Canvas_Obj.Clear();
                Updates.Clear();

                PngBitmapEncoder encoder = new PngBitmapEncoder();
                Canvas_Obj[1] = can;
                Transform transform = can.LayoutTransform;

                // reset current transform incase of scalling or rotating
                can.LayoutTransform = null;

                // get size of canvas
                Size size = new Size(can.Width, can.Height);

                // measure and arrange the canvas
                can.Measure(size);
                can.Arrange(new Rect(size));

                // create and render surface and push bitmap to it
                RenderTargetBitmap renderBitmap = new RenderTargetBitmap((Int32)size.Width, (Int32)size.Height, 100d, 100d, PixelFormats.Pbgra32);

                // now render surface to bitmap
                renderBitmap.Render(can);

                // puch rendered bitmap into it
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));

                encoder1 = encoder;

                //passing encoder to plotreceiver module
                returnEncoderImage();

                //// create image to return
                //Image returnImage = new Image();
                //// set source of image as frame
                //returnImage.Source = encoder.Frames[0];

                //// restore previously saved layout
                //can.LayoutTransform = transform;

                ////check if the directory exists or not and if not exist create a new one.
                //if (!Directory.Exists(imagepath))
                //    Directory.CreateDirectory(imagepath);

                //// string for saving
                //String tempPath = imagepath + "\\image.png";

                //// create a file stream for saving image
                //using (FileStream outStream = new FileStream(tempPath, FileMode.Create))
                //{
                //    encoder.Save(outStream);
                //}
                
            }
            #region code
            else if (pane_number == -2)
            {
                Canvas_Obj.Clear();
                Updates.Clear();


                PngBitmapEncoder encoder = new PngBitmapEncoder();
                Canvas_Obj[1] = can;
                Viewport3D vi = new Viewport3D();
                vi = (Viewport3D)can.Children[0];
                Transform transform = vi.LayoutTransform;
                //TextBlock txt = new TextBlock() { Text = "Plot3D" };
                // reset current transform incase of scalling or rotating
                vi.LayoutTransform = null;

                // get size of canvas
                Size size = new Size(vi.Width, vi.Height);

                // measure and arrange the canvas
                vi.Measure(size);
                vi.Arrange(new Rect(size));

                // create and render surface and push bitmap to it
                RenderTargetBitmap renderBitmap = new RenderTargetBitmap((Int32)size.Width, (Int32)size.Height, 100d, 100d, PixelFormats.Pbgra32);

                // now render surface to bitmap
                renderBitmap.Render(vi);

                // puch rendered bitmap into it
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));

                encoder1 = encoder;

                //passing encoder to plotreceiver module
                returnEncoderImage();

                //// create image to return
                //Image returnImage = new Image();
                //// set source of image as frame
                //returnImage.Source = encoder.Frames[0];

                //// restore previously saved layout
                //vi.LayoutTransform = transform;

                ////check if the directory exists or not and if not exist create a new one.
                //if (!Directory.Exists(imagepath))
                //    Directory.CreateDirectory(imagepath);

                //// string for saving
                //String tempPath = imagepath + "\\image.png";

                //// create a file stream for saving image
                //using (FileStream outStream = new FileStream(tempPath, FileMode.Create))
                //{
                //    encoder.Save(outStream);
                //}

            }
            #endregion
            else
            {
                object a=can.Tag;
                if((string)a=="subplot3D_Terrain"|| (string)a=="subplot3D_Vector")
                {
                    //Canvas_Obj.Clear();
                    //Updates.Clear();
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                //Canvas_Obj[1] = can;

                int resized_pane_number = 0;

                Canvas resized_canvas = new Canvas();
                foreach (DictionaryEntry entry in Canvas_Obj)
                {

                    Canvas canvas_value = (Canvas)entry.Value;
                    if (canvas_value.Height != can.Height)
                    {
                        resized_canvas = resize_canvas(canvas_value, pane_number);
                        resized_pane_number = FindKey(canvas_value);
                        Updates.Add(resized_pane_number, resized_canvas);
                    }
                }
                foreach (DictionaryEntry upd in Updates)
                {
                    Canvas_Obj[upd.Key] = upd.Value;
                }


                Canvas_Obj[pane_number] = can;
                Canvas cannew = new Canvas();
                cannew = mergePlots();
               // Viewport3D vi = new Viewport3D();
                //vi = (Viewport3D)can.Children[0];
                Transform transform = cannew.LayoutTransform;
                //TextBlock txt = new TextBlock() { Text = "Plot3D" };
                // reset current transform incase of scalling or rotating
                cannew.LayoutTransform = null;

                // get size of canvas
                Size size = new Size(cannew.Width, cannew.Height);

                // measure and arrange the canvas
                cannew.Measure(size);
                cannew.Arrange(new Rect(size));

                // create and render surface and push bitmap to it
                RenderTargetBitmap renderBitmap = new RenderTargetBitmap((Int32)size.Width, (Int32)size.Height, 100d, 100d, PixelFormats.Pbgra32);

                // now render surface to bitmap
                renderBitmap.Render(cannew);

                // puch rendered bitmap into it
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));

                encoder1 = encoder;

                //passing encoder to plotreceiver module
                returnEncoderImage();

                // create image to return
                Image returnImage = new Image();
                // set source of image as frame
                returnImage.Source = encoder.Frames[0];

                // restore previously saved layout
                cannew.LayoutTransform = transform;

                //check if the directory exists or not and if not exist create a new one.
                if (!Directory.Exists(imagepath))
                    Directory.CreateDirectory(imagepath);

                // string for saving
                String tempPath = imagepath + "\\image.png";

                // create a file stream for saving image
                using (FileStream outStream = new FileStream(tempPath, FileMode.Create))
                {
                    encoder.Save(outStream);
                }

                }
                else 
                {
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                int resized_pane_number = 0;

                Canvas resized_canvas = new Canvas();


                //IDictionaryEnumerator entry = Canvas_Obj.GetEnumerator();
                foreach (DictionaryEntry entry in Canvas_Obj)
                {

                    Canvas canvas_value = (Canvas)entry.Value;
                    if (canvas_value.Height != can.Height)
                    {
                        resized_canvas = resize_canvas(canvas_value, pane_number);
                        resized_pane_number = FindKey(canvas_value);
                        Updates.Add(resized_pane_number, resized_canvas);
                    }
                }
                foreach (DictionaryEntry upd in Updates)
                {
                    Canvas_Obj[upd.Key] = upd.Value;
                }


                Canvas_Obj[pane_number] = can;
                Canvas cannew = new Canvas();
                cannew = mergePlots();



                Transform transform = can.LayoutTransform;

                // reset current transform incase of scalling or rotating
                can.LayoutTransform = null;

                // get size of canvas
                Size size = new Size(cannew.Width, cannew.Height);

                // measure and arrange the canvas 
                cannew.Measure(size);
                cannew.Arrange(new Rect(size));

                // create and render surface and push bitmap to it
                RenderTargetBitmap renderBitmap = new RenderTargetBitmap((Int32)size.Width, (Int32)size.Height, 100d, 100d, PixelFormats.Pbgra32);

                // now render surface to bitmap
                renderBitmap.Render(cannew);

                // puch rendered bitmap into it
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                encoder1 = encoder;

                //passing encoder to plotreceiver module
                returnEncoderImage();

                // create image to return
                Image returnImage = new Image();
                // set source of image as frame
                returnImage.Source = encoder.Frames[0];

                // restore previously saved layout
                can.LayoutTransform = transform;

                //check if the directory exists or not and if not exist create a new one.
                if (!Directory.Exists(imagepath))
                    Directory.CreateDirectory(imagepath);

                // string for saving
                String tempPath = imagepath + "\\image.png";

                // create a file stream for saving image
                using (FileStream outStream = new FileStream(tempPath, FileMode.Create))
                {
                    encoder.Save(outStream);
                }
            }
            }

        }