Drawing Images

Drawing Lines

This example uses Graphics class to draw the line shapes on the Image surface. To demonstrate the operation, the example creates a new Image in BMP format and draws lines on the Image surface using draw_line method exposed by Graphics class. First, we will create an instance of FileSteram and then we will create an object of the BmpOptions class from aspose.imaging.imageoptions namespace and set its various properties. The most important property is the source property, the source property actually determines where the image data will reside (in the file or stream) and in this case it is a stream. After setting these properties, pass this object to the static create method of the Image class along with height and width parameters.

Once the image has been created, we will use the clear method exposed by the Graphics class to set its background color. The draw_line method of the Graphics class is used to draw a line on an image connecting two point structures. This method has several overloads accepting the instance of Pen class and coordinates pairs of points or Point/PointF structures as arguments. The Pen Class defines an object used to draw lines, curves and figures. The Pen class has several overloaded constructors to draw lines with specified color, width & brush. The SolidBrush class is used for drawing continuously with specific color. The following code snippet shows you how to draw the line shapes on the Image surface.

}}

Drawing Ellipse

Drawing ellipse example is the second article in the drawing shapes series. We will use Graphics class to draw the ellipse shape on the Image surface. To demonstrate the operation, the example creates a new Image in BMP format and draws ellipse shape on the Image surface using draw_ellipse method exposed by Graphics class. First, we will create an object of the BmpOptions class from aspose.imaging.imageoptions namespace and set its various properties e.g. Source property, the Source property actually determines where the image data will reside (in the file or stream) and in this case it is a stream. After setting these properties, pass this object to the static create method of the Image class along with height and width arguments.

After creating image, we will create and initialize Graphics class object and set image background color using the Clear method of the Graphics class. The DrawEllipse method of the Graphics class is used to draw ellipse shape on an image surface specified by the bounding rectangle structure. This method has several overloads accepting the instances of the Pen and Rectangle/RectangleF classes or a pair of coordinates, a height, and a width as arguments. The Pen class defines an object used to draw lines, curves and figures. The Pen class has several overloaded constructors to draw lines with specified color, width & brush. The Rectangle class stores a set of four integers that represent the location and size of a rectangle. The Rectangle class has several overloaded constructors to draw the rectangle structure with specified size and location. The SolidBrush class is used for drawing continuously with specific color. The following code snippet shows you how to draw ellipse shape on the Image surface.

}}

Drawing Rectangle

In this example we will draw the rectangle shape on the Image surface. To demonstrate the operation, the example creates a new Image in BMP format and draw rectangle shape on the Image surface using draw_rectangle method exposed by Graphics class. First, we will create an object of the BmpOptions class from aspose.imaging.imageoptions namespace and set its various properties. The most important property is the Source property, the Source property actually determines where the image data will reside (in the file or stream) and in this case it is a stream. After setting these properties, pass this object to the static create method of the Image class. Then, we will set the background color of the Image by using the clear method of the Graphics class.

The draw_rectangle method of the Graphics class is used to draw rectangle shape on an image surface specified by the rectangle structure. This method has several overloads accepting the instances of the Pen and Rectangle/RectangleF classes or coordinate pair, a width, and a height as arguments. The Rectangle class stores a set of four integers that represent the location and size of a rectangle. The Rectangle class has several overloaded constructors to draw the rectangle structure with specified size and location. The following code snippet shows you how to rectangle shape on the Image surface.

}}

Drawing Arc

In this session of drawing shape series, we will draw the Arc shape on the Image surface. We will use draw_arc method of Graphics to demonstrate the operation on a BMP image. First, we will create an object of the BMPOptions class from aspose.imaging.imageoptions namespace and set its various properties. The most important property is the Source property. This property actually determines where the image data will reside (in the file or stream) and in this case it is a stream. After setting these properties, pass this object to the static create method of the Image class to create a new BMP image. Once the image has been created, we will use the clear method exposed by the Graphics class to set its background color.

The draw_arc method of the Graphics class is used to draw the Arc shape on an image surface. draw_arc represent a portion of an ellipse specified by the rectangle structure or pair of the coordinates. This method has several overloads accepting the instances of the Pen classes and Rectangle /RectangleF structure or a pair of the coordinates, a width, and a height as arguments. The following code snippet shows you how to draw Arc shape on the Image surface.

}}

Drawing Bezier

This example uses Graphics class to draw the Bezier shape on the Image surface. To demonstrate the operation, the example creates a new Image in BMP format and draw Bezier shape on the Image surface using draw_bezier method exposed by Graphics class. First, we will create an object of the BmpOptions class from aspose.imaging.imageoptions namespace and set its various properties. The most important property is the Source property. This property actually determines where the image data will reside (in the file or stream) and in this case it is a stream. After setting these properties, pass this object to the static create method of the Image class.Once the image has been created, we will use the clear method exposed by the Graphics class to set its background color.

The draw_bezier method of the Graphics class is used to draw Bezier spline shape on an image surface defined by four Point structures. This method has several overloads accepting the instances of the Pen class and four ordered pair of coordinates or four Point/PointF structures or array of Point/PointF structures. The Pen class defines an object used to draw lines, curves and figures. The Pen class has several overloaded contractors to draw lines with specified color, width & brush. The following code snippet shows you how to draw the bezier shape on the Image surface.

}}

Drawing Images using Core Functionality

Aspose.Imaging is an imaging library that offers many valuable features including creating images from scratch. Draw using the core functionality like manipulating an image’s bitmap information, or use the advanced features like Graphics and GraphicsPath to draw shapes on image surface with the help of different brushes and pens. Using Aspose.Imaging’s RasterImage class, you can retrieve an image area’s pixel information manipulate it. The RasterImage class contains the entire core drawing functionality, like getting and setting pixels and other methods for image manipulation. Create a new image using any of the methods described in Creating Files and assign it to an instance of the RasterImage class. Use the RasterImage class' load_pixels method to retrieve the pixel information of a portion of an image. Once you have an array of pixels, you can manipulate it by, for example, changing the color of each pixel. After manipulating the pixel information, set it back to the desired area in the image using the RasterImage class' save_pixels method. The following code snippet shows you how to draw images using core functionality.

}}