[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.Drawing.IShape.ToImage

ToImage Method

ToImage(string)

Saves the shape to the specified image file.

The generated image displays the rectangular worksheet area enclosed by the shape. This method can be used with shapes such as AutoShapes, pictures, slicers, and charts.

Declaration
void ToImage(string fileName)
Sub ToImage(fileName As String)
Parameters
Type Name Description
string fileName

The output image file.

Examples
IShape shape = worksheet.Shapes.AddShape(AutoShapeType.Oval, 20, 20, 160, 80);
string imagePath = "ShapeToImage.png";
shape.ToImage(imagePath);

ToImage(string, ImageSaveOptions)

Saves the shape to the specified image file using options.

The generated image displays the rectangular worksheet area enclosed by the shape. This method can be used with shapes such as AutoShapes, pictures, slicers, and charts. Use options to control how the output image is generated.

Declaration
void ToImage(string fileName, ImageSaveOptions options)
Sub ToImage(fileName As String, options As ImageSaveOptions)
Parameters
Type Name Description
string fileName

The output image file.

ImageSaveOptions options

The options for output image.

Examples
IShape shape = worksheet.Shapes.AddShape(AutoShapeType.Oval, 20, 20, 160, 80);
ImageSaveOptions options = new ImageSaveOptions();
options.ScaleX = 2.0;
string imagePath = "ShapeToImage.png";
shape.ToImage(imagePath, options);

ToImage(Stream, ImageType)

Saves the shape to the specified image stream.

Use imageType to control the output format of the generated image. To customize the exported image, use ToImage(Stream, ImageType, ImageSaveOptions).

Declaration
void ToImage(Stream stream, ImageType imageType)
Sub ToImage(stream As Stream, imageType As ImageType)
Parameters
Type Name Description
Stream stream

The output image stream to receive the generated image. This value cannot be null.

ImageType imageType

Specifies the type of image to create.

Examples
IShape shape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.Name = "SalesBox";
MemoryStream stream = new MemoryStream();
shape.ToImage(stream, ImageType.PNG);

ToImage(Stream, ImageType, ImageSaveOptions)

Saves the shape to the specified image stream using options.

Use this method to export the current shape as an image in the specified format. The generated image is written to the provided Stream.

Declaration
void ToImage(Stream stream, ImageType imageType, ImageSaveOptions options)
Sub ToImage(stream As Stream, imageType As ImageType, options As ImageSaveOptions)
Parameters
Type Name Description
Stream stream

The output image stream.

ImageType imageType

Specifies the type of image to create.

ImageSaveOptions options

The options for output image. This value can be null.

Examples
IShape shape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
MemoryStream stream = new MemoryStream();
ImageSaveOptions options = new ImageSaveOptions();
shape.ToImage(stream, ImageType.PNG, options);