Class LowCodeImageSaveOptions

LowCodeImageSaveOptions class

Options for saving image in low code way.

public class LowCodeImageSaveOptions : LowCodeSaveOptions

Constructors

NameDescription
LowCodeImageSaveOptions()The default constructor.

Properties

NameDescription
ImageOptions { get; set; }The options for rendering images.
OutputFile { get; set; }Gets and sets the file(with path if needed) for saving the generated data. When setting this property with value other than null or empty string, OutputStream will be ignored.(Inherited from LowCodeSaveOptions.)
OutputStream { get; set; }Gets and sets the Stream for writing the generated data to. When setting this property with value other than null, OutputFile will be ignored.(Inherited from LowCodeSaveOptions.)
override SaveFormat { get; set; }Gets or sets the save format.
SaveOptionsProvider { get; set; }Provider of save options for saving generated images.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.LowCode;
    using Aspose.Cells.Rendering;
    using System;

    public class LowCodeClassLowCodeImageSaveOptionsDemo
    {
        public static void Run()
        {
            // Create a new workbook for demonstration
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            try
            {
                // Add sample data to the worksheet
                worksheet.Cells["A1"].PutValue("LowCode Image Save Demo");
                worksheet.Cells["A2"].PutValue("This demonstrates LowCodeImageSaveOptions");

                // Create an instance of LowCodeImageSaveOptions
                LowCodeImageSaveOptions saveOptions = new LowCodeImageSaveOptions();

                // Set basic properties
                saveOptions.SaveFormat = SaveFormat.Png;
                saveOptions.ImageOptions = new ImageOrPrintOptions();

                // Display current settings
                Console.WriteLine("SaveFormat: " + saveOptions.SaveFormat);
                Console.WriteLine("ImageOptions HorizontalResolution: " +
                    saveOptions.ImageOptions.HorizontalResolution);

                // Modify some image options
                saveOptions.ImageOptions.HorizontalResolution = 300;
                saveOptions.ImageOptions.VerticalResolution = 300;

                // Create a simple save options provider
                saveOptions.SaveOptionsProvider = new SimpleSaveOptionsProvider();

                // Save the worksheet as an image
                SheetRender renderer = new SheetRender(worksheet, saveOptions.ImageOptions);
                renderer.ToImage(0, "LowCodeImageOutput.png");

                Console.WriteLine("Image saved successfully with LowCodeImageSaveOptions");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error working with LowCodeImageSaveOptions: {ex.Message}");
            }
        }
    }

    public class SimpleSaveOptionsProvider : AbstractLowCodeSaveOptionsProvider
    {
        public override LowCodeSaveOptions GetSaveOptions(SplitPartInfo part)
        {
            return new LowCodeImageSaveOptions()
            {
                SaveFormat = SaveFormat.Png,
                ImageOptions = new ImageOrPrintOptions()
                {
                    HorizontalResolution = 300,
                    VerticalResolution = 300
                }
            };
        }

        public override void Finish(LowCodeSaveOptions part)
        {
            Console.WriteLine("Finished saving part");
        }
    }
}

See Also