当前位置: 首页>>代码示例>>C#>>正文


C# Shape.GetShapeRenderer方法代码示例

本文整理汇总了C#中Shape.GetShapeRenderer方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.GetShapeRenderer方法的具体用法?C# Shape.GetShapeRenderer怎么用?C# Shape.GetShapeRenderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shape的用法示例。


在下文中一共展示了Shape.GetShapeRenderer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindShapeSizes

        public static void FindShapeSizes(Shape shape)
        {
            //ExStart
            //ExFor:ShapeRenderer.SizeInPoints
            //ExId:ShapeRendererSizeInPoints
            //ExSummary:Demonstrates how to find the size of a shape in the document and the size of the shape when rendered.
            SizeF shapeSizeInDocument = shape.GetShapeRenderer().SizeInPoints;
            float width = shapeSizeInDocument.Width; // The width of the shape.
            float height = shapeSizeInDocument.Height; // The height of the shape.
            //ExEnd

            //ExStart
            //ExFor:ShapeRenderer.GetSizeInPixels
            //ExId:ShapeRendererGetSizeInPixels
            //ExSummary:Shows how to create a new Bitmap and Graphics object with the width and height of the shape to be rendered.
            // We will render the shape at normal size and 96dpi. Calculate the size in pixels that the shape will be rendered at.
            Size shapeRenderedSize = shape.GetShapeRenderer().GetSizeInPixels(1.0f, 96.0f);

            using (Bitmap image = new Bitmap(shapeRenderedSize.Width, shapeRenderedSize.Height))
            {
                using (Graphics g = Graphics.FromImage(image))
                {
                    // Render shape onto the graphics object using the RenderToScale or RenderToSize methods of ShapeRenderer class.
                }
            }
            //ExEnd
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:27,代码来源:Program.cs

示例2: RenderShapeToGraphics

        public static void RenderShapeToGraphics(string dataDir, Shape shape)
        {
            ShapeRenderer r = shape.GetShapeRenderer();

            // Find the size that the shape will be rendered to at the specified scale and resolution.
            Size shapeSizeInPixels = r.GetSizeInPixels(1.0f, 96.0f);

            // Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
            // and make sure that the graphics canvas is large enough to compensate for this.
            int maxSide = Math.Max(shapeSizeInPixels.Width, shapeSizeInPixels.Height);

            using (Bitmap image = new Bitmap((int)(maxSide * 1.25), (int)(maxSide * 1.25)))
            {
                // Rendering to a graphics object means we can specify settings and transformations to be applied to 
                // the shape that is rendered. In our case we will rotate the rendered shape.
                using (Graphics gr = Graphics.FromImage(image))
                {
                    // Clear the shape with the background color of the document.
                    gr.Clear(shape.Document.PageColor);
                    // Center the rotation using translation method below
                    gr.TranslateTransform((float)image.Width / 8, (float)image.Height / 2);
                    // Rotate the image by 45 degrees.
                    gr.RotateTransform(45);
                    // Undo the translation.
                    gr.TranslateTransform(-(float)image.Width / 8, -(float)image.Height / 2);

                    // Render the shape onto the graphics object.
                    r.RenderToSize(gr, 0, 0, shapeSizeInPixels.Width, shapeSizeInPixels.Height);
                }
                dataDir = dataDir + "TestFile.RenderToGraphics_out_.png";
                image.Save(dataDir, ImageFormat.Png);

                Console.WriteLine("\nShape rendered to graphics successfully.\nFile saved at " + dataDir);
            }
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:35,代码来源:RenderShape.cs

示例3: RenderShapeToDisk

        public static void RenderShapeToDisk(string dataDir, Shape shape)
        {
            ShapeRenderer r = shape.GetShapeRenderer();

            // Define custom options which control how the image is rendered. Render the shape to the JPEG raster format.
            ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Emf)
            {
                Scale = 1.5f
            };

            dataDir = dataDir + "TestFile.RenderToDisk_out_.emf";
            // Save the rendered image to disk.
            r.Save(dataDir, imageOptions);

            Console.WriteLine("\nShape rendered to disk successfully.\nFile saved at " + dataDir);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:16,代码来源:RenderShape.cs

示例4: RenderShapeToDisk

        public static void RenderShapeToDisk(string dataDir, Shape shape)
        {
            //ExStart
            //ExFor:ShapeRenderer
            //ExFor:ShapeBase.GetShapeRenderer
            //ExFor:ImageSaveOptions
            //ExFor:ImageSaveOptions.Scale
            //ExFor:ShapeRenderer.Save(String, ImageSaveOptions)
            //ExId:RenderShapeToDisk
            //ExSummary:Shows how to render a shape independent of the document to an EMF image and save it to disk.
            // The shape render is retrieved using this method. This is made into a separate object from the shape as it internally
            // caches the rendered shape.
            ShapeRenderer r = shape.GetShapeRenderer();

            // Define custom options which control how the image is rendered. Render the shape to the JPEG raster format.
            ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Emf)
            {
                Scale = 1.5f
            };

            // Save the rendered image to disk.
            r.Save(dataDir + "TestFile.RenderToDisk Out.emf", imageOptions);
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:24,代码来源:Program.cs

示例5: RenderNode

        //ExStart
        //ExId:RenderNode
        //ExSummary:Shows how to render a node independent of the document by building on the functionality provided by ShapeRenderer class.
        /// <summary>
        /// Renders any node in a document to the path specified using the image save options.
        /// </summary>
        /// <param name="node">The node to render.</param>
        /// <param name="path">The path to save the rendered image to.</param>
        /// <param name="imageOptions">The image options to use during rendering. This can be null.</param>
        public static void RenderNode(Node node, string filePath, ImageSaveOptions imageOptions)
        {
            // Run some argument checks.
            if (node == null)
                throw new ArgumentException("Node cannot be null");

            // If no image options are supplied, create default options.
            if (imageOptions == null)
                imageOptions = new ImageSaveOptions(FileFormatUtil.ExtensionToSaveFormat(Path.GetExtension(filePath)));

            // Store the paper color to be used on the final image and change to transparent.
            // This will cause any content around the rendered node to be removed later on.
            Color savePaperColor = imageOptions.PaperColor;
            imageOptions.PaperColor = Color.Transparent;

            // There a bug which affects the cache of a cloned node. To avoid this we instead clone the entire document including all nodes,
            // find the matching node in the cloned document and render that instead.
            Document doc = (Document)node.Document.Clone(true);
            node = doc.GetChild(NodeType.Any, node.Document.GetChildNodes(NodeType.Any, true).IndexOf(node), true);

            // Create a temporary shape to store the target node in. This shape will be rendered to retrieve
            // the rendered content of the node.
            Shape shape = new Shape(doc, ShapeType.TextBox);
            Section parentSection = (Section)node.GetAncestor(NodeType.Section);

            // Assume that the node cannot be larger than the page in size.
            shape.Width = parentSection.PageSetup.PageWidth;
            shape.Height = parentSection.PageSetup.PageHeight;
            shape.FillColor = Color.Transparent; // We must make the shape and paper color transparent.

            // Don't draw a surronding line on the shape.
            shape.Stroked = false;

            // Move up through the DOM until we find node which is suitable to insert into a Shape (a node with a parent can contain paragraph, tables the same as a shape).
            // Each parent node is cloned on the way up so even a descendant node passed to this method can be rendered. 
            // Since we are working with the actual nodes of the document we need to clone the target node into the temporary shape.
            Node currentNode = node;
            while (!(currentNode.ParentNode is InlineStory || currentNode.ParentNode is Story || currentNode.ParentNode is ShapeBase))
            {
                CompositeNode parent = (CompositeNode)currentNode.ParentNode.Clone(false);
                currentNode = currentNode.ParentNode;
                parent.AppendChild(node.Clone(true));
                node = parent; // Store this new node to be inserted into the shape.
            }

            // We must add the shape to the document tree to have it rendered.
            shape.AppendChild(node.Clone(true));
            parentSection.Body.FirstParagraph.AppendChild(shape);

            // Render the shape to stream so we can take advantage of the effects of the ImageSaveOptions class.
            // Retrieve the rendered image and remove the shape from the document.
            MemoryStream stream = new MemoryStream();
            shape.GetShapeRenderer().Save(stream, imageOptions);
            shape.Remove();

            // Load the image into a new bitmap.
            using (Bitmap renderedImage = new Bitmap(stream))
            {
                // Extract the actual content of the image by cropping transparent space around
                // the rendered shape.
                Rectangle cropRectangle = FindBoundingBoxAroundNode(renderedImage);

                Bitmap croppedImage = new Bitmap(cropRectangle.Width, cropRectangle.Height);
                croppedImage.SetResolution(imageOptions.Resolution, imageOptions.Resolution);

                // Create the final image with the proper background color.
                using (Graphics g = Graphics.FromImage(croppedImage))
                {
                    g.Clear(savePaperColor);
                    g.DrawImage(renderedImage, new Rectangle(0, 0, croppedImage.Width, croppedImage.Height), cropRectangle.X, cropRectangle.Y, cropRectangle.Width, cropRectangle.Height, GraphicsUnit.Pixel);
                    croppedImage.Save(filePath);
                }
            }
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:83,代码来源:Program.cs

示例6: RenderShapeToGraphics

        public static void RenderShapeToGraphics(string dataDir, Shape shape)
        {
            //ExStart
            //ExFor:ShapeRenderer
            //ExFor:ShapeBase.GetShapeRenderer
            //ExFor:ShapeRenderer.GetSizeInPixels
            //ExFor:ShapeRenderer.RenderToSize
            //ExId:RenderShapeToGraphics
            //ExSummary:Shows how to render a shape independent of the document to a .NET Graphics object and apply rotation to the rendered image.
            // The shape renderer is retrieved using this method. This is made into a separate object from the shape as it internally
            // caches the rendered shape.
            ShapeRenderer r = shape.GetShapeRenderer();

            // Find the size that the shape will be rendered to at the specified scale and resolution.
            Size shapeSizeInPixels = r.GetSizeInPixels(1.0f, 96.0f);

            // Rotating the shape may result in clipping as the image canvas is too small. Find the longest side
            // and make sure that the graphics canvas is large enough to compensate for this.
            int maxSide = Math.Max(shapeSizeInPixels.Width, shapeSizeInPixels.Height);

            using (Bitmap image = new Bitmap((int)(maxSide * 1.25), (int)(maxSide * 1.25)))
            {
                // Rendering to a graphics object means we can specify settings and transformations to be applied to 
                // the shape that is rendered. In our case we will rotate the rendered shape.
                using (Graphics gr = Graphics.FromImage(image))
                {
                    // Clear the shape with the background color of the document.
                    gr.Clear(Color.White);
                    // Center the rotation using translation method below
                    gr.TranslateTransform((float)image.Width / 8, (float)image.Height / 2);
                    // Rotate the image by 45 degrees.
                    gr.RotateTransform(45);
                    // Undo the translation.
                    gr.TranslateTransform(-(float)image.Width / 8, -(float)image.Height / 2);

                    // Render the shape onto the graphics object.
                    r.RenderToSize(gr, 0, 0, shapeSizeInPixels.Width, shapeSizeInPixels.Height);
                }

                image.Save(dataDir + "TestFile.RenderToGraphics.png", ImageFormat.Png);
            }
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:43,代码来源:Program.cs

示例7: RenderDrawingMLToDisk

 public static void RenderDrawingMLToDisk(string dataDir, Shape drawingML)
 {
     //ExStart
     //ExFor:DrawingML.GetShapeRenderer
     //ExFor:ShapeRenderer.Save(String, ImageSaveOptions)
     //ExFor:DrawingML
     //ExId:RenderDrawingMLToDisk
     //ExSummary:Shows how to render a DrawingML image independent of the document to a JPEG image on the disk.
     // Save the DrawingML image to disk in JPEG format and using default options.
     drawingML.GetShapeRenderer().Save(dataDir + "TestFile.RenderDrawingML Out.jpg", null);
     //ExEnd
 }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:12,代码来源:Program.cs

示例8: RenderShapeImage

 public static void RenderShapeImage(string dataDir, Shape shape)
 {
     // ExStart:RenderShapeImage
     dataDir = dataDir + "TestFile.RenderShape_out.jpg";
     // Save the Shape image to disk in JPEG format and using default options.
     shape.GetShapeRenderer().Save(dataDir, null);
     // ExEnd:RenderShapeImage
     Console.WriteLine("\nShape image rendered successfully.\nFile saved at " + dataDir);
 }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:9,代码来源:RenderShape.cs


注:本文中的Shape.GetShapeRenderer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。