Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
1Spring 2002
© University of Stirling
IT82: Multimedia 1
Spring 2002
© University of Stirling
IT82: Multimedia 2
Overview
• Graphics in Java:
– Colour
– Images
– Java2D
– Fonts
• The bigger picture of Java Graphics:
– Java Advanced Imaging (JAI) API
– Java3D
• The bigger picture of Java multimedia
2Spring 2002
© University of Stirling
IT82: Multimedia 3
Java2D
• Java 2D extends the basic AWT graphics facilities
• New in Java 2 (with JDK version 1.2)
• A brief overview:
– Draw lines of any thickness
– Fill shapes with gradients and textures
– Move, rotate, scale, and shear text and graphics
– Composite overlapping text and graphics
– Filters, enabling simple image operations, e.g.
• blurring
• sharpening
Spring 2002
© University of Stirling
IT82: Multimedia 4
Colour Models
• In Java2D, the java.awt.color package provides
colours
• All the common colour spaces are provided, including
– standard RGB
– greyscale colour models
– CMY, CMYK,
– HSV
– CIE XYZ
– CIE Lab,
– and more!
• Typical usage:
– (alpha,red,green,blue) is stored as an int in the RGB
colour model
3Spring 2002
© University of Stirling
IT82: Multimedia 5
Image Types
• Image
– in java.awt
– abstract superclass of all classes for representing images
• ImageIcon
– class provided by Swing, for using as icons
– implements Icon
• BufferedImage
– direct subclass of Image
– in java.awt.image
– pixel data available for manipulation
Spring 2002
© University of Stirling
IT82: Multimedia 6
Buffered Images
bufferedIm.getRGB(15,10)
15
10
4Spring 2002
© University of Stirling
IT82: Multimedia 7
What is a graphics context?
public void paint(Graphics g) {
  g.setColor(Color.red);
  g.drawRect(100,100,60,40);
}
A graphics context (an instance of the Graphics class)
holds contextual information for doing drawing operations:
Spring 2002
© University of Stirling
IT82: Multimedia 8
Graphics2D
Paint on a component (use paintComponent in Swing):
public void paint(Graphics g) {
  g.setColor(Color.red);
  g.drawRect(100,100,60,40);
}
…or create a graphics context for drawing on an image:
Graphics2D g2 = bufferedIm.createGraphics();
g2.setColor(Color.red);
g2.drawRect(100,100,60,40);
A Graphics2D object holds state information
5Spring 2002
© University of Stirling
IT82: Multimedia 9
Graphics2D State
• Stroke
setStroke
• Paint
setPaint
• Composite
setComposite
• Transform
setTransform
• Clip
setClip
• Font
setFont
• RenderingHints
setRenderingHints
Spring 2002
© University of Stirling
IT82: Multimedia 10
Shapes and Painting
g2.drawRect(100,100,60,40);
6Spring 2002
© University of Stirling
IT82: Multimedia 11
Stroking
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.magenta);
  BasicStroke stroke = new BasicStroke(2.0f);
  g2d.setStroke(stroke);
  g2d.draw(new Rectangle2D.Double(40,40,60,40));
  BasicStroke wideStroke = new BasicStroke(8.0f);
  g2d.setStroke(wideStroke);
  g2d.draw(new
RoundRectangle2D.Double(40,120,60,40, 10, 10));
}
Spring 2002
© University of Stirling
IT82: Multimedia 12
Transformations (affine)
• Rotation
• Translating (moving)
• Reflection
• Shearing (stretching)
• Scaling
7Spring 2002
© University of Stirling
IT82: Multimedia 13
Example: Rotation
Spring 2002
© University of Stirling
IT82: Multimedia 14
Compositing Rules
Various!
8 different
rules
altogether
8Spring 2002
© University of Stirling
IT82: Multimedia 15
Compositing Rule: XOR Mode
Spring 2002
© University of Stirling
IT82: Multimedia 16
Rendering Hints
• Rendering hints are not guaranteed to be obeyed
• Various available, including
– dithering
– anti-aliasing
9Spring 2002
© University of Stirling
IT82: Multimedia 17
The Java2D Graphics Pipeline
Graphic
Primitive Transformation
Clipping
Rasterizer
Painting
Compositing Rule
Spring 2002
© University of Stirling
IT82: Multimedia 18
Java Advanced Imaging (JAI)
• Extends features provided in the Java2D API, in the
area of image input, manipulation and output
• Greater range of file formats (for input/output)
– GIF (Compuserve’s Graphics Interchange Format)
– JPEG (a way of compressing images from the Joint
Photographics Experts Group)
– PNG (Portable Network Graphics)
– TIF (Tag Image File Format)
– BMP (Microsoft’s bitmap format)
– PNM (Portably aNy Map format - includes PBM,PGM,PPM)
– FPX (FlashPix)
10
Spring 2002
© University of Stirling
IT82: Multimedia 19
JAI
• Greater range of colour models
• Conversion methods between different colour spaces
are also provided
• ColorSpaces provided include
– RGB, non-colour-corrected RGB,
– Grayscale, CMY/CMYK
– CIE XYZ, Lab
– Lab, HSV,
– a luminance (g)/chrominance (colour) standard for Kodak
PhotoCD images
Spring 2002
© University of Stirling
IT82: Multimedia 20
JAI
• More ways to model images than just
BufferedImage, e.g.
– Tiled Images
– Image Sequences
– Multi-resolution Images
• Methods for extracting data from images, e.g.
– finding the frequency of occurrence of colours in images
– finding the “edges” (or outlines) in an image
– other statistical operations on the pixel data
11
Spring 2002
© University of Stirling
IT82: Multimedia 21
JAI
• Many, many methods for image manipulation, e.g.
• Combining (compositing) two images in various ways
• Image enhancement, e.g.
– Sharpening
– Blurring
• Transformations - not just geometric, but also...
Spring 2002
© University of Stirling
IT82: Multimedia 22
– Perspective
– Warping
12
Spring 2002
© University of Stirling
IT82: Multimedia 23
Java3D
Spring 2002
© University of Stirling
IT82: Multimedia 24
Java Media APIs
• Java2D
• Java Advanced Imaging (JAI)
• Java3D
• Java Media Framework
– audio, video, time-based media
• Java Sound
– audio, midi
• Java Speech
– speech technology including digital recognition, speech
synthesisers
– only 3rd party implementations