Packages

 

com.aspose.imaging

Interfaces

Classes

Exceptions

com.aspose.imaging

Class Brush

    • Constructor Detail

      • Brush

        public Brush()
    • Method Detail

      • getOpacity

        public float getOpacity()

        Gets the brush opacity. The value should be between 0 and 1. Value of 0 means that brush is fully visible, value of 1 means the brush is fully opaque.

        Returns:
        The brush opacity value.
      • setOpacity

        public void setOpacity(float value)

        Sets the brush opacity. The value should be between 0 and 1. Value of 0 means that brush is fully visible, value of 1 means the brush is fully opaque.

        Parameters:
        value - The brush opacity value.
        Code example:

        This example uses Graphics class to create primitive shapes on the Image surface. To demonstrate the operation, the example creates a new Image in PNG format and draw primitive shapes on Image surface using Draw methods exposed by Graphics class


        // Creates an instance of FileStream
        com.aspose.imaging.system.io.FileStream stream = new com.aspose.imaging.system.io.FileStream("C:\\temp\\output.png", com.aspose.imaging.system.io.FileMode.Create);
        try {
            // Create an instance of PngOptions and set its various properties
            com.aspose.imaging.imageoptions.PngOptions pngOptions = new com.aspose.imaging.imageoptions.PngOptions();
        
            // Set the Source for PngOptions
            pngOptions.setSource(new com.aspose.imaging.sources.StreamSource(stream));
        
            // Create an instance of Image
            com.aspose.imaging.Image image = com.aspose.imaging.Image.create(pngOptions, 500, 500);
            try {
                // Create and initialize an instance of Graphics class
                com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
        
                // Clear Graphics surface
                graphics.clear(com.aspose.imaging.Color.getWheat());
        
                // Draw an Arc by specifying the Pen object having Black com.aspose.imaging.Color,
                // a Rectangle surrounding the Arc, Start Angle and Sweep Angle
                graphics.drawArc(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getBlack(), 2),
                        new com.aspose.imaging.Rectangle(200, 200, 100, 200),
                        0,
                        300);
        
                // Draw a Bezier by specifying the Pen object having Blue com.aspose.imaging.Color and co-ordinate Points.
                graphics.drawBezier(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getBlue(), 2),
                        new com.aspose.imaging.Point(250, 100),
                        new com.aspose.imaging.Point(300, 30),
                        new com.aspose.imaging.Point(450, 100),
                        new com.aspose.imaging.Point(235, 25));
        
                // Draw a Curve by specifying the Pen object having Green com.aspose.imaging.Color and an array of Points
                graphics.drawCurve(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getGreen(), 2),
                        new com.aspose.imaging.Point[]
                                {
                                        new com.aspose.imaging.Point(100, 200),
                                        new com.aspose.imaging.Point(100, 350),
                                        new com.aspose.imaging.Point(200, 450)
                                });
        
                // Draw an Ellipse using the Pen object and a surrounding Rectangle
                graphics.drawEllipse(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getYellow(), 2),
                        new com.aspose.imaging.Rectangle(300, 300, 100, 100));
        
                // Draw a Line
                graphics.drawLine(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getViolet(), 2),
                        new com.aspose.imaging.Point(100, 100),
                        new com.aspose.imaging.Point(200, 200));
        
                // Draw a Pie segment
                graphics.drawPie(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getSilver(), 2),
                        new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(200, 20), new com.aspose.imaging.Size(200, 200)),
                        0,
                        45);
        
                // Draw a Polygon by specifying the Pen object having Red com.aspose.imaging.Color and an array of Points
                graphics.drawPolygon(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getRed(), 2),
                        new com.aspose.imaging.Point[]
                                {
                                        new com.aspose.imaging.Point(20, 100),
                                        new com.aspose.imaging.Point(20, 200),
                                        new com.aspose.imaging.Point(220, 20)
                                });
        
                // Draw a Rectangle
                graphics.drawRectangle(
                        new com.aspose.imaging.Pen(com.aspose.imaging.Color.getOrange(), 2),
                        new com.aspose.imaging.Rectangle(new com.aspose.imaging.Point(250, 250), new com.aspose.imaging.Size(100, 100)));
        
                // Create a SolidBrush object and set its various properties
                com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush();
                brush.setColor(com.aspose.imaging.Color.getPurple());
                brush.setOpacity(100f);
        
                // Draw a String using the SolidBrush object and Font, at specific Point
                graphics.drawString(
                        "This image is created by Aspose.Imaging API",
                        new com.aspose.imaging.Font("Times New Roman", 16),
                        brush,
                        new com.aspose.imaging.PointF(50, 400));
        
                // Save all changes.
                image.save();
            } finally {
                image.dispose();
            }
        } finally {
            stream.dispose();
        }
        

      • deepClone

        public Brush deepClone()

        Creates a new deep clone of the current Brush.

        Returns:
        A new Brush which is the deep clone of this Brush instance.