Shape.ToImage

ToImage(Stream, ImageType)

Creates the shape image and saves it to a stream in the specified format.

public void ToImage(Stream stream, ImageType imageType)
ParameterTypeDescription
streamStreamThe output stream.
imageTypeImageTypeThe type in which to save the image.

Remarks

The following formats are supported: .bmp, .gif, .jpg, .jpeg, .tiff, .emf.

Examples

using System;
using System.IO;
using Aspose.Cells;
using Aspose.Cells.Drawing;

namespace AsposeCellsExamples
{
    public class ShapeMethodToImageWithStreamImageTypeDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Add a sample shape with correct parameters
            Shape shape = worksheet.Shapes.AddRectangle(1, 0, 0, 100, 200, 0);

            // Convert shape to image stream
            using (MemoryStream imageStream = new MemoryStream())
            {
                shape.ToImage(imageStream, ImageType.Png);
                Console.WriteLine("Shape converted to image stream successfully");
            }
        }
    }
}

See Also


ToImage(string, ImageOrPrintOptions)

Saves the shape to a file.

public void ToImage(string imageFile, ImageOrPrintOptions options)

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Drawing;
using Aspose.Cells.Rendering;

namespace AsposeCellsExamples
{
    public class ShapeMethodToImageWithStringImageOrPrintOptionsDemo
    {
        public static void Run()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Add a sample shape with all required parameters
            Shape shape = worksheet.Shapes.AddRectangle(1, 0, 1, 100, 100, 100);

            // Set image options
            ImageOrPrintOptions options = new ImageOrPrintOptions()
            {
                HorizontalResolution = 300,
                VerticalResolution = 300
            };

            // Save shape to image
            shape.ToImage("shape_image.png", options);
        }
    }
}

See Also


ToImage(Stream, ImageOrPrintOptions)

Saves the shape to a stream.

public void ToImage(Stream stream, ImageOrPrintOptions options)

Examples


[C#]
MemoryStream imageStream = new MemoryStream();
ImageOrPrintOptions op = new ImageOrPrintOptions();
shape.ToImage(imageStream, op);

See Also


ToImage(ImageOrPrintOptions)

Returns the bitmap object of the shape .

public Bitmap ToImage(ImageOrPrintOptions options)

Examples


[C#]
ImageOrPrintOptions op = new ImageOrPrintOptions();
System.Drawing.Bitmap btm = shape.ToImage(op);

See Also