ImageDataBiLevel Property |
Namespace: Aspose.Words.Drawing
The default value is false.
// Open a document that contains images Document imgSourceDoc = new Document(MyDir + "Images.docx"); Shape sourceShape = (Shape)imgSourceDoc.GetChildNodes(NodeType.Shape, true)[0]; Document dstDoc = new Document(); // Import a shape from the source document and append it to the first paragraph, effectively cloning it Shape importedShape = (Shape)dstDoc.ImportNode(sourceShape, true); dstDoc.FirstSection.Body.FirstParagraph.AppendChild(importedShape); // Get the ImageData of the imported shape ImageData imageData = importedShape.ImageData; imageData.Title = "Imported Image"; // If an image appears to have no borders, its ImageData object will still have them, but in an unspecified color Assert.AreEqual(4, imageData.Borders.Count); Assert.AreEqual(Color.Empty, imageData.Borders[0].Color); Assert.True(imageData.HasImage); // This image is not linked to a shape or to an image in the file system Assert.False(imageData.IsLink); Assert.False(imageData.IsLinkOnly); // Brightness and contrast are defined on a 0-1 scale, with 0.5 being the default value imageData.Brightness = 0.8d; imageData.Contrast = 1.0d; // Our image will have a lot of white now that we've changed the brightness and contrast like that // We can treat white as transparent with the following attribute imageData.ChromaKey = Color.White; // Import the source shape again, set it to black and white importedShape = (Shape)dstDoc.ImportNode(sourceShape, true); dstDoc.FirstSection.Body.FirstParagraph.AppendChild(importedShape); importedShape.ImageData.GrayScale = true; // Import the source shape again to create a third image, and set it to BiLevel // Unlike greyscale, which preserves the brightness of the original colors, // BiLevel sets every pixel to either black or white, whichever is closer to the original color importedShape = (Shape)dstDoc.ImportNode(sourceShape, true); dstDoc.FirstSection.Body.FirstParagraph.AppendChild(importedShape); importedShape.ImageData.BiLevel = true; // Cropping is determined on a 0-1 scale // Cropping a side by 0.3 will crop 30% of the image out at that side importedShape.ImageData.CropBottom = 0.3d; importedShape.ImageData.CropLeft = 0.3d; importedShape.ImageData.CropTop = 0.3d; importedShape.ImageData.CropRight = 0.3d; dstDoc.Save(ArtifactsDir + "Drawing.ImageData.docx");