Java's drawing world - Java 2D

zhaozj2021-02-16  72

Sender: TTLINK (Skywalker), the letter area: Java Title: Java's drawing world - Java 2D send station: Sun and Moonlight (December 20, 2002 01:23 Friday), station letter

Http://www.cn-java.com/target/news.php?news_id=1984

I. Introduction Java 2D API is a member of JFC (Java Fundation Classes), strengthens the drawing of traditional AWT (AbstractWindowing Toolkit). Java 2D has been supported in JDK1.2. Through the Java2D API, Programmer can easily depict the alternative geometry, using different filling effects, rotate, zoom, scaling, twisted (SHEAR). As shown in the figure, PROGRAMMER transmits a statistical diagram with different types of lines or filling effects through the function provided by the 2D API to distinguish between different materials. Of course, 2D API has many parts that enhance the AWT capabilities, like processing video files, can have different filter (Filter) effect, can also do collision detection, graphic overlapping color calculation for any geometry. (Composite) and so on. These techniques will be summonized in the text. Second, Java 2D API PACKAGES JDK1.2 About 2D API Packages As described below: 2. Java.awt java.aw contains some new 2D API categories (interfaces). Where Graphics2D inherits from Java.awt.graphics, it is an object that depicts 2D graphics. Like the drawing mode used by the previous version of JDK, when some objects are to be depicted, Paint or Update Method automatically proceeds to draw in the appropriate Graphics Context. The so-called Graphics Context is a collection of graphics object-related status properties (State Attribute). Many status properties have been added in Graphics2D, such as stroke, Paint, Clip, Transform, etc. 2.2 java.awt.geom java.awt.geom includes the GeneralPath category that can be submitted. It can be composed of many different kinds of Subpath, like Lines and Quadratic Curves, etc. In order to take care of the convenience, many basic geometry are defined in this package, including Arc2D, CubicCurve2D, Line2D, and the like. These categories have two types, namely Float Precision and Double Precision. In addition, there is a special graphic category: Area, which supports Constructive Area Geometry (CGA). The CGA is a process of generating a new graphic object for both a Boolean Operation that existing graphics objects. As shown in Figure 2, the AREAS Support, an Intersection, a Subtraction, an Exclusive or (XOR). Finally, the AffineTransform category provides conversion on scale, shear, and rotate, etc..

2.3 java.awt.font java.awt.font Defines the TextLayout category. Responsible for constructing text shape, performing appropriate textoperties, such as collision detection and lightning, etc., and determining the appropriate location and order of Text. 2.4 Java.awt.Image Java 2D API supports three imaging modes. Including Producter / Consumer (Push) Model, ImmediateMode Model and Pipeine (Pull) Model. Push Model supports in the previous version of JDK. PULL MODEL supports in the upcoming Java Advanced Imaging AP. Here, we only explore the immediate mode immediate mode immediate mode immediate mode imaging model in JDK1.2. Under this MODEL, Programmer can do the effect of Make Image Data (BufferedImage or Raster) through the 2D API. In PackageJava.awt.Image, Immediate Mode Imaging APIS can be classified as six categories: Interfaces, Image Data Classes, Image Operation Classes, Sample Model Classes, ColorModel Classes, and Exceptions. The Operation Classes defines many filters, including AffInTransformop, BandcomBineop, ColorConvertop, Convolveop, Lookup, Rescaleop, and so on. Through the above films, you can do effects such as Geometric or Transform, Blur, Sharpen, Enhance Contrast, Threshold and Color Correct Images. As shown in Figure 3, Source Image has a new graphic. 2.5 java.awt.color package java.awt.color Defines Class Colorspace. This class provides the Method of the Programmer converted color disc. 2.6 Java.awt.Print Java Printing API provides a Method for Programmer printing AWT and Java 2D Graphics (Composit Edgraphics, and Imagees). And let the user set the properties of the print, such as double-sided printing, etc. Third, Java 2D Programming initially solves the Package Information of the Java 2D API, and can further achieve some simple Applications to recognize the wonderful. Before that, let's learn some basic 2D programing codes. 3.1 Basic Steps The first step of the drawing is to generate Graphics2D Object. Then you set the status properties you want. For example, you want to make a gravel filling of a piece of item, you can set the properties Paint as GradientPaint. Finally, call the Redering Method, Fill, or DRAW provided by Graphics2D, and complete the entire drawing program.

The following is the example of this basic step: import java.awt. *; Import java.awt.geom. *; Public void Paint (graphics g) {Ellipse2d.float shape; gradientpaint gp; // create a graphics2d graphics2d g2 = (Graphics2D) g; // Create A Ellipse2D (x, y, w, h) shape = new elipse2d.float (200, 200, 60, 60); // Create a cyclic gradientpaint // (x1, y1, color1, x2 , Y2, Color2, Boolean Cyclic) GP = New GradientPaint (180, 190, Color.yellow, 220, 210, Color.Red, true); g2.setpaint (gp); g2.fill (shape);} 3.2 How to draw line in JDK has not yet Before the support 2D graphics, Programmer can only draw straight, the same thick lines. Now, we teach you how to paint different thick lines and smooth curves through 2D API. Classes such as Line2D, Quadcurve2D, and Cubiccurve2d is available in PackageJava.awt.Geom, allowing Programmer to easily draw the wanted lines. The paradigm is as follows: import java.awt.geom. *; ... line2d.float line; cubiccurve2d.float copi; // crete a line2d line = new line2d.float (20,390,200,390); // Create a cubiccurve2d, straight line There are more than two control points Cubic = New Cubiccurve2D.float (70, 100, 120, 50, 170, 270, 220, 100); // Set the drawn thickness G2. SetStroke (New Basicstroke (2.0F)); g2.setcolor (color.blue); g2.draw Line); line = new line2d.float (30, 400, 250, 400); // Set the drawn thickness G2. setStroke (New Basicstroke (5.0F)); g2.draw (line); 3.3 Display strings Transmit by Java 2D, Programmer Show more detailed text. If the example of the paradigm code: Shows the outer skewers "font test" outside the light blue. Import java.awt.font. *; ... shape sha; fontrenderContext frc = g2.GetFontrenderContext (); TextLayout TL = New TextLayout ("Font Test", New Font ("Modern", Font.Bold Font.Italic, 20) , FRC); SHA = TL.GetOutline (AffineTransform.GettranslateInstance (50, 380)); g2.setColor (color.blue); g2.setStroke (New Basicstroke (2.0F)); g2.draw (SHA); g2.setColor COLOR.WHITE); G2.FILL (SHA); 3.4 Before the graphics are desired, if the graphic has the effect of the filter, you must help with a drawing software that can handle graphics.

转载请注明原文地址:https://www.9cbs.com/read-17316.html

New Post(0)