1 / 14

JAVA 2D API

JAVA 2D API. 簡介 影像 載入影像 Applet (Image) Application (Image) JPEG (BufferedImage) 顯示影像 Graphics Graphics2D. 簡介. JAVA 2D API 是 JAVA 2 的一組 core API, 可以用來進行繪圖並處理圖形 , 文字 , 影像 JDK 1.0 和 JDK1.1: Abstract Windowing Toolkit , AWT Java 2: AWT 使用者介面工具組 UI toolkit ( Swing )

Download Presentation

JAVA 2D API

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA 2D API

  2. 簡介 • 影像 • 載入影像 • Applet (Image) • Application (Image) • JPEG (BufferedImage) • 顯示影像 • Graphics • Graphics2D

  3. 簡介 • JAVA 2D API 是 JAVA 2 的一組core API,可以用來進行繪圖並處理圖形,文字,影像 • JDK 1.0 和 JDK1.1: • Abstract Windowing Toolkit , AWT • Java 2: • AWT • 使用者介面工具組 UI toolkit ( Swing ) • 繪圖工具組 ( 2D API )

  4. 影像 • java.awt.image ~ 矩形的彩色像素集合 • public abstract int getWidth(ImageObserver observer) • public abstract int getHeight(ImageObserver observer) • Java.awt.image.BufferedImage~ 可直接存取 • public int getWidth() • public int getHeight()

  5. 載入影像(Applet) • 格式: GIF JPEG ( Image ) • Applet(java.applet.Applet ) • public Image getImage(URL url) • public Image getImage(URL url, String name)

  6. 載入影像(Application 1) • Application ( java.awt.Toolkit) • public abstract Image getImage (URL url) • Public abstract Image getImage (URL url, String filename) • 透過呼叫Toolkit.getDefaultToolkit() Image mImage = Toolkit.getDefaultToolkit().getImage(“washer.gif”) • 會存在cache 中

  7. 載入影像(Application 2) • Application( java.awt.Toolkit) • public abstract Image createImage (URL url) • Public abstract Image createImage (URL url, String filename) • 不會存在cache 中

  8. JPEG編碼解碼器 • com.sun.image.codec.jpeg • codec ~ encoder/decoder • Public static JPEGImageDecoder createJPEGDecoder( InputStream src ) • Public static JPEGImageEncoder createJPEGEncoder( OutputStream src ) String filname = “washer.jpg”; FileInputStream in = new FileInputStream(filename); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in); BufferImage image = decoder.decoderAsBufferedImage(); In.close();

  9. 顯示影像(Graphics 1) • public boolean drawImage (Image img, int x, int y,Color bgcolor, ImageObserver observer ) • 依圖片大小來呈現 • 原圖 呈現 (x,y)

  10. 顯示影像(Graphics 2) • public boolean drawImage(Image img, int x, int y, int width, int height,Color bgcolor, ImageObserver observer) • 以 x, y, width, height 決定的矩形來調整影像大小 • 原圖 呈現 (x,y) w h

  11. 顯示影像(Graphics 3) • public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int dx2,intdy2,Color bgcolor, ImageObserver observer) • 影像空間座標 使用者空間座標 (sx1,sy1) (dx1,dy1) (sx2,sy2) (dx2,dy2)

  12. 顯示影像(Graphics2D) • Public void drawImage (Image img, AffineTransform xform, ImageObserver observer) • Public void drawImage (BufferedImage img, BufferedImageOP op, int x, int y) • 呈現處理過的BufferedImage,並不會改變原來的BufferedImage

  13. ImageObserver • 在Graphics 和 Graphics2D中的drawImage() method都支援ImageObserver來監控下載的進程 • 開始下載通知ImageObserver • ImageObserver  repaint() drawImage()

  14. BufferedImage • BufferedImageOp代表影像處理的操作,他知道如何處理source image來產生destination image 來源 BufferedImage 目的地 BufferedImage BufferedImageOp

More Related