Graphics 2D 1 Subject : T0934 / Multimedia Programming Foundation

advertisement
Graphics 2D 1
Subject
Session
Tahun
Versi
:
:
:
:
T0934 / Multimedia Programming Foundation
6
2009
1/0
Learning Outcomes
In the end of this session, students must be
able to:
– Understand the basic principal of
Java2D Graphics
– Apply correct Java syntax to use
Java2D Graphics
Bina Nusantara
Outline
• Font
• 2D Graphics
• Java 2D Graphics
Bina Nusantara
Font - Characters
Letters
(ABC)
Symbols
(~!@)
Digits
(123)
Language
Bina Nusantara
Sentences
Words
Characters
(Alphabets)
Character Codes
Character
Code
ASCII
ISO
Latin 1
Unicode
ISO
10646
Bina Nusantara
A group of characters, each assigned with a
unique numerical code
American Standard Code for Information
Interchange, 7 bits , commonly used in the US and
abroad
alias ISO 8859-1 , 8 bits, commonly used for
computer processing
16 bits, include characters from all known
languages and alphabets in the world (multilingual
text and character encoding)
32 bits, defines UCS (Universal Character Set)
Characters & Glyphs
Characters
represented
in a visual
display
Glyphs
organized in
one set
Fonts
• One character can be represented as several glyphs
A
A
A
A
A
• Two or more characters can be represented in one
glyphs
Bina Nusantara
Fonts
• Size
– measured in points (1 point = 1/72 inch)
• Style
– Bold, Italic, Underline, superscript, subscript , etc
• Classification
Bitmap
• Glyphs are
represented in
bitmap (raster)
• blocky and less
legible if enlarge
Bina Nusantara
PostScript
TrueType
• developed by
Adobe
• scalable
• require Adobe
Type Manager
(ATM) software to
look smooth
• good for design
and publishing
• not cross platform
compatible
• jointly developed
by Apple and
Microsoft
• scalable
• not cross platform
compatible
• everyone can
make a new TT
font
OpenType
• jointly developed
by Apple and
Microsoft
• scalable
• not supported by
all application
• cross platform
compatible
Font Spacing
• all characters have the same width
• used for typewriter/newspaper
• characters’ width varies with the shape
• easier to read
• used for textbook
Bina Nusantara
Font
Font is accessible as long as
installed in your computer.
Font use only setFont and
drawString.
Bina Nusantara
Graphics
An engine to display
graphic primitives on
output devices
Graphic
Primitives
• Shapes
• Images
• Text
Bina Nusantara
Rendering
Engine
• Java
graphics2D
Output
Devices
• Screens
• Printers
Graphics
•
•
•
•
•
•
Coordinates
Shapes
Stroke
Fill
Composite
Antialiasing
Bina Nusantara
Coordinates
• User space – The space in which graphics
primitives are specified
• Device space – The coordinate system of an
output device such as a screen, window, or a
printer
X
0
Y
Bina Nusantara
Coordinates
User Space
transform user
space into
device space
Device Space
Graphic
Primitives
Rendering
Engine
Output
Devices
Bina Nusantara
Coordinates
An example to know the coordinate of
mouse click in an image.
Use MouseListener.
Full code is downloadable in Additional
Material.
Bina Nusantara
Shapes
• Point
• Lines
• Rectangular Shapes
• Quadratic and Cubic Curves
Bina Nusantara
Shapes
An example showing
how to make an
Ellipse Shape
Bina Nusantara
Stroke
• An outline of lines /dashing patterns on a
graphic primitive
Solid
Round Dot
Thickness & Color
Bina Nusantara
Dash
Long Dash Dot
Stroke
We add these codes to the previous code of
shape, and we get strokes.
Full code is downloadable in Additional
Material.
Bina Nusantara
Fill
• Interior of a graphic primitive
Solid
Bina Nusantara
Gradient
Texture/
Pattern
Image
Fill
We add these codes to the previous code of
shape, and we get gradient paint to fill.
Full code is downloadable in Additional
Material.
Bina Nusantara
Composite
• Adding new objects on existing objects
Composite
Bina Nusantara
Composite
We add two shapes and for the second one
we apply AlphaComposite to blend them
together.
Full code is downloadable in Additional
Material.
Bina Nusantara
Antialiasing
Aliasing
Bina Nusantara
Antialiasing
Antialiasing
Antialiasing is used to smooth
the curve of the font.
In this example, “W” is smooth
enough, even though it is
enlarged.
Bina Nusantara
Java 2D Graphics
Graphic
Primitives
Bina Nusantara
Rendering
Engine
Output
Devices
References
•
•
•
•
•
•
•
•
•
•
Java2D: An Introduction and Tutorial. 1998.
http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html
2D Drawing. 2008. http://courses.coreservlets.com/Course-Materials/java5.html
Character Sets / Character Encoding Issues. 2008.
http://www.phpwact.org/php/i18n/charsets
HTML Document Representation. 2009. http://www.w3.org/TR/html4/charset.html#h5.2
Unicode Character Encoding Model. 2008.
http://www.unicode.org/unicode/reports/tr17/
A tutorial on character code issues. 2009. http://www.cs.tut.fi/~jkorpela/chars.html
Fonts: Bitmap, PostScript, and TrueType Compared. 2004.
http://support.apple.com/kb/TA21573?viewlocale=en_US
Base Monospace. 2009. http://www.emigre.com/EFfeature.php?di=80
Overview of the Java 2D API Concepts. 2008.
http://java.sun.com/docs/books/tutorial/2d/overview/index.html
Java2D: An Introduction and Tutorial. 1998.
http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html
Bina Nusantara
Download