Java Reference
In-Depth Information
Finally, Graphics2D combinesthecoloredpixels(sourcepixels)withexistingdes-
tination pixels to form new pixels according to its current composite rule.
Rasterizing and Compositing
Therasterizercreatesarectangularimagethatcontainsonlyalphavalues.Thereareno
colorsatthispoint.Analphavaluerangesfrom0(nocoverage)to255(fullcoverage),
andtheimage'scollectionofalphavaluesisknownasits alpha channel .(Alphavalues
also can be expressed as floating-point values ranging from 0.0 through 1.0.)
The rasterizer defaults to choosing alpha values of 255 or 0. Because the resulting
source pixel will either fully cover the existing destination pixel or will not cover this
pixel,lines,text,andothergeometricprimitiveswilltendtohavejaggededges.Thisis
known as aliasing .
When you specify antialiasing as a rendering hint, the rasterizer slows down some-
what (it has more work to do), but chooses a wider range of alpha values so that
graphics primitives look smoother. This smoothness derives from combining percent-
ages of source and current destination pixel red, green, and blue color components
(whosevalueseachrangefrom0[darkest]through255[brightest])sothatpartsofthe
current destination pixels show through when the new destination pixels are drawn.
The final step in the rendering process involves combining source pixels with des-
tination pixels. This step is carried out according to the current composite rule, which
determines how this combining takes place.
The composite rule takes alpha value percentages into account. For example, the
“source over” rule (which is the most intuitive) combines 100 percent of the source
pixel'scolor(dependingonitsalpha)withapercentageofthedestinationpixel'scolor,
which happens to be (255-source pixel's alpha value)/255*100.
Consider a source pixel with an alpha of255(it contributes 100percent to the final
color).Accordingtotheequation,thedestinationpixelwouldhaveanalphaof0(itcon-
tributes0percent),whichmeansthatthedestinationpixeliscompletelycovered.Ifthe
sourcepixelhasanalphaof0(itcontributesnothing),thedestinationpixelwouldhave
analphaof255(itcontributeseverything),whichmeansthatthesourcepixelisinvis-
ible.Intermediatealphavaluescombinedifferentpercentagesofsourceanddestination
pixels.
Rendering Attributes
Now that you've grasped the basics of the Graphics2D rendering pipeline, you're
readytofurtherexploreitsrenderingattributes.Tohelpyouwiththisexploration,I've
Search WWH ::




Custom Search