Java圖形處理-Java 2D
Java 2D API分為以下幾個包
java.awt.geom
提供用于在與二維幾何形狀相關的對象上定義和執行操作的 Java 2D 類。
Area 對象存儲和操作2維空間封閉區域的與解析無關的描述。
public Rectangle getBounds() 返回完全包圍此 Area 的邊界 Rectangle。
public boolean contains(double x, double y) 測試指定坐標是否在 Shape 的邊界內。
對區域進行加、減、交和異或。
public void add(Area rhs)
public void subtract(Area rhs)
public void intersect(Area rhs)
public void exclusiveOr(Area rhs)
java.awt.font 字體類
Font f = new Font(String name,int style,int size);//style Font.ITALIC
java.awt.color 顏色定義和顏色調優
java.awt.image 用于圖像定義
java.awt.image.renderable 圖像渲染
java.awt.print
java.awt.Graphics2D
以提供如何繪制圖形的信息,包含六個屬性
繪制 paint 作用在邊線和填充上
畫筆 stroke 描邊決定著圖形或文字的輪廓,邊緣即可以是粗細不等的實線,也可以是等寬點線
字體 font 所有的文本都使用能表現文字的樣式圖形渲染
轉換 transform 圖形在渲染前可能會進行一步或多步的變形 圖形可能被移動,旋轉或拉伸
剪切 clip
合成 composite
javax.imageio
Java高級圖像處理圖像I/O工具包
eg; java2D繪制直線,矩形,橢圓
package com.mapbar.graphics; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; /** * Class DrawGraphics.java * Description java2D繪制直線,矩形,橢圓,旋轉圖形 * Company mapbar * author Chenll * Version 1.0 * Date 2012-7-20 下午12:06:15 */ public class DrawGraphics{ private BufferedImage image; private Graphics2D graphics; public void init(){ int width=480,hight=720; image = new BufferedImage(width,hight,BufferedImage.TYPE_INT_RGB); //獲取圖形上下文 graphics = (Graphics2D)image.getGraphics(); } /** * 創建一個(x1,y1)到(x2,y2)的Line2D對象 * @throws IOException */ public void drawLine() throws IOException{ init(); Line2D line=new Line2D.Double(2,2,300,300); graphics.draw(line); graphics.dispose(); outImage("PNG","D:\\Line.PNG"); } /** * 創建一個左上角坐標是(50,50),寬是300,高是400的一個矩形對象 * @throws IOException */ public void drawRect() throws IOException{ init(); Rectangle2D rect = new Rectangle2D.Double(50,50,400,400); graphics.draw(rect); graphics.fill(rect); graphics.dispose(); outImage("PNG","D:\\Rect.PNG"); } /** * 創建了一個左上角坐標是(50,50),寬是300,高是200的一個橢圓對象,如果高,寬一樣,則是一個標準的圓 * * @throws IOException */ public void drawEllipse() throws IOException{ init(); Ellipse2D ellipse=new Ellipse2D.Double(50,50,300,200); graphics.draw(ellipse); graphics.fill(ellipse); graphics.dispose(); outImage("PNG","D:\\ellipse.PNG"); } /** * 輸出繪制的圖形 * @param type * @param filePath * @throws IOException */ public void outImage(String type,String filePath) throws IOException{ ImageIO.write(image,type, new File(filePath)); } public static void main(String[] args) throws IOException{ DrawGraphics dg = new DrawGraphics(); dg.drawLine(); dg.drawRect(); dg.drawEllipse(); } }轉自:http://blog.csdn.net/cdl2008sky/article/details/7768747