menu

WinUI

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Interface IPictureShape - WinUI API Reference | Syncfusion

    Show / Hide Table of Contents

    Interface IPictureShape

    Represents an Image in a worksheet.

    Inherited Members
    IParentApplication.Application
    IParentApplication.Parent
    IShape.AlternativeText
    IShape.Fill
    IShape.Height
    IShape.HeightDouble
    IShape.Hyperlink
    IShape.Id
    IShape.IsMoveWithCell
    IShape.IsShapeVisible
    IShape.IsSizeWithCell
    IShape.Left
    IShape.LeftDouble
    IShape.Line
    IShape.Name
    IShape.OnAction
    IShape.Remove()
    IShape.Scale(Int32, Int32)
    IShape.Shadow
    IShape.ShapeRotation
    IShape.ShapeType
    IShape.TextFrame
    IShape.ThreeD
    IShape.Top
    IShape.TopDouble
    IShape.Width
    IShape.WidthDouble
    Namespace: Syncfusion.XlsIO
    Assembly: Syncfusion.XlsIO.NET.dll
    Syntax
    public interface IPictureShape : IShape, IParentApplication

    Properties

    FileName

    Gets the Filename, Read only.

    Declaration
    string FileName { get; }
    Property Value
    Type
    System.String
    Examples

    The following code illustrates how to access the FileName property.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Create image stream from svg
                Stream svgStream = new FileStream("image.svg", FileMode.Open);
    
                //Create image stream from png
                Stream stream = new FileStream("image.png", FileMode.Open);
    
                //Add image
                IPictureShape picture = worksheet.Pictures.AddPicture(1, 1, svgStream, stream, 50, 50);
    
                //Check
                Console.Write(picture.FileName);
    
                //Save and dispose
                workbook.SaveAs("Shapes.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //Picture0

    Picture

    Gets or sets the picture.

    Declaration
    Image Picture { get; set; }
    Property Value
    Type
    Image
    Examples

    The following code illustrates how Picture property can be accessed.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Create image stream from svg
                Stream svgStream = new FileStream("image.svg", FileMode.Open);
    
                //Create image stream from png
                Stream stream = new FileStream("image.png", FileMode.Open);
    
                //Add image
                IPictureShape picture = worksheet.Pictures.AddPicture(1, 1, svgStream, stream, 50, 50);
    
                //Check
                Console.Write(picture.Picture != null);
    
                //Save and dispose
                workbook.SaveAs("Shapes.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //True

    SvgData

    Gets or sets the svg data for the picture.

    Declaration
    Stream SvgData { get; set; }
    Property Value
    Type
    System.IO.Stream
    Examples

    The following code illustrates how SvgData property can be accessed.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Create image stream from svg
                Stream svgStream = new FileStream("image.svg", FileMode.Open);
    
                //Create image stream from png
                Stream stream = new FileStream("image.png", FileMode.Open);
    
                //Add image
                IPictureShape picture = worksheet.Pictures.AddPicture(1, 1, svgStream, stream, 50, 50);
    
                //Check
                Console.Write(picture.SvgData != null);
    
                //Save and dispose
                workbook.SaveAs("Shapes.xlsx");
                workbook.Close();
                Console.ReadKey();
            }
    //Output will be
    //True

    Methods

    Remove(Boolean)

    Removes shape from the collection.

    Declaration
    void Remove(bool removeImage)
    Parameters
    Type Name Description
    System.Boolean removeImage

    Removes image that is referenced by this shape from collection too, if we didn't detect image usage. XlsIO doesn't detect this situation correctly in all cases if there are shapes in charts in Excel 2007 or if some image shapes are grouped in any excel version. If you are not sure whether image is referenced in charts or grouped shapes and you are working with Excel 2007 version, set this argument to true (this could cause file size increase, but will keep document in the correct state).

    Examples

    The following code illustrates how to remove a IPictureShape from IPictures collection.

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                //Create worksheet
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook workbook = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];
    
                //Add images
                IPictureShape picture = worksheet.Pictures.AddPicture(1, 1, "image.png");
                IPictureShape picture2 = worksheet.Pictures.AddPicture(1, 15, "image.png");
    
                //Remove image
                picture.Remove(true);
    
                //Save and dispose
                workbook.SaveAs("Shapes.xlsx");
                workbook.Close();
            }
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved