Click or drag to resize

ImageColorMode Enumeration

Specifies the color mode for the generated images of document pages.

Namespace:  Aspose.Words.Saving
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.5.0

ExpandedSyntax

public enum ImageColorMode

ExpandedMembers

  Member nameValueDescription
None0 The pages of the document will be rendered as color images.
Grayscale1 The pages of the document will be rendered as grayscale images.
BlackAndWhite2 The pages of the document will be rendered as black and white images.

ExpandedExamples

Shows how to set a color mode when rendering documents.
Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.ParagraphFormat.Style = doc.Styles["Heading 1"];
            builder.Writeln("Hello world!");
            builder.InsertImage(ImageDir + "Logo.jpg");

            Assert.That(20000, Is.LessThan(new FileInfo(ImageDir + "Logo.jpg").Length));

            // When we save the document as an image, we can pass a SaveOptions object to
            // select a color mode for the image that the saving operation will generate.
            // If we set the "ImageColorMode" property to "ImageColorMode.BlackAndWhite",
            // the saving operation will apply grayscale color reduction while rendering the document.
            // If we set the "ImageColorMode" property to "ImageColorMode.Grayscale", 
            // the saving operation will render the document into a monochrome image.
            // If we set the "ImageColorMode" property to "None", the saving operation will apply the default method
            // and preserve all the document's colors in the output image.
            ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);
            imageSaveOptions.ImageColorMode = imageColorMode;

            doc.Save(ArtifactsDir + "ImageSaveOptions.ColorMode.png", imageSaveOptions);

#if NET462 || JAVA
            switch (imageColorMode)
            {
                case ImageColorMode.None:
                    Assert.That(150000, Is.LessThan(new FileInfo(ArtifactsDir + "ImageSaveOptions.ColorMode.png").Length));
                    break;
                case ImageColorMode.Grayscale:
                    Assert.That(80000, Is.LessThan(new FileInfo(ArtifactsDir + "ImageSaveOptions.ColorMode.png").Length));
                    break;
                case ImageColorMode.BlackAndWhite:
                    Assert.That(20000, Is.AtLeast(new FileInfo(ArtifactsDir + "ImageSaveOptions.ColorMode.png").Length));
                    break;
            }
#elif NETCOREAPP2_1
            switch (imageColorMode)
            {
                case ImageColorMode.None:
                    Assert.That(120000, Is.LessThan(new FileInfo(ArtifactsDir + "ImageSaveOptions.ColorMode.png").Length));
                    break;
                case ImageColorMode.Grayscale:
                    Assert.That(80000, Is.LessThan(new FileInfo(ArtifactsDir + "ImageSaveOptions.ColorMode.png").Length));
                    break;
                case ImageColorMode.BlackAndWhite:
                    Assert.That(20000, Is.AtLeast(new FileInfo(ArtifactsDir + "ImageSaveOptions.ColorMode.png").Length));
                    break;
            }
#endif

ExpandedSee Also