Packages

 

com.aspose.imaging.brushes

Class HatchBrush

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public final class HatchBrush
    extends Brush

    Defines a rectangular brush with a hatch style, a foreground color, and a background color. This class cannot be inherited.

    Code example:

    This example shows the creation and usage Pen objects. The example creates a new Image and draw Rectangles on Image surface.


    
    // Create an instance of BmpOptions and set its various properties
    com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions();
    bmpOptions.setBitsPerPixel(24);
    
    // Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
    // Second Boolean parameter determines if the file to be created IsTemporal or not
    bmpOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false));
    
    // Create an instance of Image at specified Path
    com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500);
    try {
        // Create an instance of Graphics and initialize it with Image object
        com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
    
        // Clear the Graphics sutface with White Color
        graphics.clear(com.aspose.imaging.Color.getWhite());
    
        // Create an instance of Pen with color Red and width 5
        com.aspose.imaging.Pen pen = new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 5);
    
        // Create an instance of HatchBrush and set its properties
        com.aspose.imaging.brushes.HatchBrush brush = new com.aspose.imaging.brushes.HatchBrush();
        brush.setBackgroundColor(com.aspose.imaging.Color.getWheat());
        brush.setForegroundColor(com.aspose.imaging.Color.getRed());
    
        // Create an instance of Pen and initialize it with HatchBrush object and width
        com.aspose.imaging.Pen brushedpen = new com.aspose.imaging.Pen(brush, 5);
    
        // Draw Rectangles by specifying Pen object
        graphics.drawRectangles(pen, new com.aspose.imaging.Rectangle[]
                {
                        new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(210, 210), new com.aspose.imaging.Size(100, 100)),
                        new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 110), new com.aspose.imaging.Size(100, 100)),
                        new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 310), new com.aspose.imaging.Size(100, 100))
                });
    
        // Draw Rectangles by specifying Pen object
        graphics.drawRectangles(
                brushedpen,
                new com.aspose.imaging.Rectangle[]
                        {
                                new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 110), new com.aspose.imaging.Size(100, 100)),
                                new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 310), new com.aspose.imaging.Size(100, 100))
                        });
    
        // Save all changes.
        image.save();
    } finally {
        image.dispose();
    }
    

    • Constructor Detail

      • HatchBrush

        public HatchBrush()
    • Method Detail

      • getForegroundColor

        public Color getForegroundColor()

        Gets the color of hatch lines.

        Returns:
        The color of hatch lines.
      • setForegroundColor

        public void setForegroundColor(Color value)

        Sets the color of hatch lines.

        Parameters:
        value - The color of hatch lines.
        Code example:

        This example shows the creation and usage Pen objects. The example creates a new Image and draw Rectangles on Image surface.


        
        // Create an instance of BmpOptions and set its various properties
        com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions();
        bmpOptions.setBitsPerPixel(24);
        
        // Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
        // Second Boolean parameter determines if the file to be created IsTemporal or not
        bmpOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false));
        
        // Create an instance of Image at specified Path
        com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500);
        try {
            // Create an instance of Graphics and initialize it with Image object
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
        
            // Clear the Graphics sutface with White Color
            graphics.clear(com.aspose.imaging.Color.getWhite());
        
            // Create an instance of Pen with color Red and width 5
            com.aspose.imaging.Pen pen = new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 5);
        
            // Create an instance of HatchBrush and set its properties
            com.aspose.imaging.brushes.HatchBrush brush = new com.aspose.imaging.brushes.HatchBrush();
            brush.setBackgroundColor(com.aspose.imaging.Color.getWheat());
            brush.setForegroundColor(com.aspose.imaging.Color.getRed());
        
            // Create an instance of Pen and initialize it with HatchBrush object and width
            com.aspose.imaging.Pen brushedpen = new com.aspose.imaging.Pen(brush, 5);
        
            // Draw Rectangles by specifying Pen object
            graphics.drawRectangles(pen, new com.aspose.imaging.Rectangle[]
                    {
                            new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(210, 210), new com.aspose.imaging.Size(100, 100)),
                            new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 110), new com.aspose.imaging.Size(100, 100)),
                            new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 310), new com.aspose.imaging.Size(100, 100))
                    });
        
            // Draw Rectangles by specifying Pen object
            graphics.drawRectangles(
                    brushedpen,
                    new com.aspose.imaging.Rectangle[]
                            {
                                    new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 110), new com.aspose.imaging.Size(100, 100)),
                                    new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 310), new com.aspose.imaging.Size(100, 100))
                            });
        
            // Save all changes.
            image.save();
        } finally {
            image.dispose();
        }
        

      • getBackgroundColor

        public Color getBackgroundColor()

        Gets the color of spaces between the hatch lines.

        Returns:
        The color of spaces between the hatch lines.
      • setBackgroundColor

        public void setBackgroundColor(Color value)

        Sets the color of spaces between the hatch lines.

        Parameters:
        value - The color of spaces between the hatch lines.
        Code example:

        This example shows the creation and usage Pen objects. The example creates a new Image and draw Rectangles on Image surface.


        
        // Create an instance of BmpOptions and set its various properties
        com.aspose.imaging.imageoptions.BmpOptions bmpOptions = new com.aspose.imaging.imageoptions.BmpOptions();
        bmpOptions.setBitsPerPixel(24);
        
        // Create an instance of FileCreateSource and assign it as Source for the instance of BmpOptions
        // Second Boolean parameter determines if the file to be created IsTemporal or not
        bmpOptions.setSource(new com.aspose.imaging.sources.FileCreateSource("C:\\temp\\sample.bmp", false));
        
        // Create an instance of Image at specified Path
        com.aspose.imaging.Image image = com.aspose.imaging.Image.create(bmpOptions, 500, 500);
        try {
            // Create an instance of Graphics and initialize it with Image object
            com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
        
            // Clear the Graphics sutface with White Color
            graphics.clear(com.aspose.imaging.Color.getWhite());
        
            // Create an instance of Pen with color Red and width 5
            com.aspose.imaging.Pen pen = new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 5);
        
            // Create an instance of HatchBrush and set its properties
            com.aspose.imaging.brushes.HatchBrush brush = new com.aspose.imaging.brushes.HatchBrush();
            brush.setBackgroundColor(com.aspose.imaging.Color.getWheat());
            brush.setForegroundColor(com.aspose.imaging.Color.getRed());
        
            // Create an instance of Pen and initialize it with HatchBrush object and width
            com.aspose.imaging.Pen brushedpen = new com.aspose.imaging.Pen(brush, 5);
        
            // Draw Rectangles by specifying Pen object
            graphics.drawRectangles(pen, new com.aspose.imaging.Rectangle[]
                    {
                            new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(210, 210), new com.aspose.imaging.Size(100, 100)),
                            new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 110), new com.aspose.imaging.Size(100, 100)),
                            new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 310), new com.aspose.imaging.Size(100, 100))
                    });
        
            // Draw Rectangles by specifying Pen object
            graphics.drawRectangles(
                    brushedpen,
                    new com.aspose.imaging.Rectangle[]
                            {
                                    new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(310, 110), new com.aspose.imaging.Size(100, 100)),
                                    new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(110, 310), new com.aspose.imaging.Size(100, 100))
                            });
        
            // Save all changes.
            image.save();
        } finally {
            image.dispose();
        }
        

      • getHatchStyle

        public int getHatchStyle()

        Gets the hatch style of this brush.

      • setHatchStyle

        public void setHatchStyle(int value)

        Sets the hatch style of this brush.