The following example introduces how an image can be created in OEDepict TK to generate a single black line across an image:
Create an OEImage object with a specific width and height.
Specify the two end points of the line with OE2DPoint objects.
Write the image into a file by calling the OEWriteImage function.
The OEImage class is implemented as a container of drawing commands. When a method such as OEImage.DrawLine is called, rather than immediately drawing the line specified by the parameters, a line drawing operation is created in the OEImage class for later execution.
Listing 1: Example of line drawing
width, height = 100, 100 # Create image image = oedepict.OEImage(width, height) # Draw line with default pen bgn = oedepict.OE2DPoint(10.0, 10.0) end = oedepict.OE2DPoint(90.0, 90.0) image.DrawLine(bgn, end, oedepict.OEBlackPen) # Write image to SVG file oedepict.OEWriteImage("DrawLine.svg", image)
The coordinate system used in OEDepict TK has the origin (x=0.0, y=0.0) at the top left with the x-axis pointing to the right and the y-axis pointing down.
OEDepict TK supports drawing the following basic shapes:
OEDepict TK natively supports a variety of graphical file formats. OEWriteImage automatically detects the desired file format from the file name passed to the function. The following table lists the file formats natively supported in OEDepict TK and their associated file extensions:
|Graphics File Format||Format Type||File Extension|
|PNG (Portable Network Graphics)||raster image||.png|
|SVG (Scalable Vector Graphics)||vector image||.svg|
|bare SVG (with no header)||vector image||.bsvg|
|Encapsulated PostScript||vector image||.eps|
|PDF (Portable Document Format)||vector image|
The OEIsRegisteredImageFile function can be used to query whether a given file extension is supported by OEDepict TK. All the supported file formats can be queried using the OEGetSupportedImageFileExtensions function.