|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.graph2.Output
org.faceless.graph2.ImageOutput
public class ImageOutput
The ImageOutput class is a subclass of Output, which allows Graphs to be drawn to a
BufferedImage
or Graphics2D
object, and then optionally rendered to
a PNG image by calling the writePNG()
method. Most commonly, the
image will be rendered to a PNG like so:
Graph graph = makeMyGraph(); ImageOutput out = new ImageOutput(400,400); graph.draw(out); out.writePNG(outputstream, 256);It's also possible to get at the generated image by calling
getImage()
for use in an applet or similar, or to write to a different file format.
This class has it's "Default" font set to the Font
"Helvetica"
Constructor Summary | |
---|---|
ImageOutput(Graphics2D graphics,
int width,
int height)
Create a new ImageOutput which will draw to the specified Graphics2D object. |
|
ImageOutput(int width,
int height)
Create a new ImageOutput of the specified width and height with a white background |
|
ImageOutput(int width,
int height,
Paint background)
Create a new ImageOutput of the specified width, height and background color. |
Method Summary | |
---|---|
Map |
getAreas()
Return a Map containing information about the areas used in the graph. |
BufferedImage |
getImage()
Return the Image created by the Graph.draw(org.faceless.graph2.Output) method. |
BufferedImage |
getReducedColorImage(int numcolors,
Color mask)
Return the Image created by the Graph.draw(org.faceless.graph2.Output) method, after
it's been reduced to the specified number of colors. |
void |
setFont(String name,
Font font)
Define a custom mapping from the specified font description to the specified font. |
void |
setMargin(int left,
int top,
int right,
int bottom)
Set the margin between the graph and the edge of the image. |
void |
setRenderingHint(RenderingHints.Key key,
Object val)
Set a rendering hint for drawing the image. |
void |
storeAreas(boolean store)
Whether to store the areas used by each object on the Graph. |
void |
writePNG(OutputStream out,
int numcolors)
Write the image as a PNG to the specified OutputStream . |
void |
writePNG(OutputStream out,
int numcolors,
int dpi)
Write the image as a PNG to the specified OutputStream . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ImageOutput(int width, int height)
width
- the width of the image in pixelsheight
- the height of the image in pixelspublic ImageOutput(int width, int height, Paint background)
width
- the width of the image in pixelsheight
- the height of the image in pixelsbackground
- the color to use as the background color, or null
for no background (ie. the background is transparent)public ImageOutput(Graphics2D graphics, int width, int height)
Graphics2D
object.
This constructor can be used when the graph is to be drawn to an existing object, such as a
Swing component. Usually the setMargin
method is called as well, to
control the area of the graphics object to write to.
graphics
- the Graphics2D object to render towidth
- the width of the Graphics2D objectheight
- the height of the Graphics2D objectMethod Detail |
---|
public void setRenderingHint(RenderingHints.Key key, Object val)
RenderingHints.KEY_ANTIALIASING = RenderingHints.VALUE_ANTIALIAS_ON RenderingHints.KEY_TEXT_ANTIALIASING = RenderingHints.VALUE_TEXT_ANTIALIAS_ON RenderingHints.KEY_RENDERING = RenderingHints.VALUE_RENDER_QUALITY RenderingHints.KEY_INTERPOLATION = RenderingHints.VALUE_INTERPOLATION_BICUBIC
public void setMargin(int left, int top, int right, int bottom)
top
- the top margin in pixelsleft
- the left margin in pixelsright
- the right margin in pixelsbottom
- the bottom margin in pixelspublic void setFont(String name, Font font)
output.setFont("myfont", Font.createFont("myfont.ttf"));
name
- the name of the font, as passed to TextStyle.setFont(java.lang.String, double)
. A
name of "Default" will override the default font. The name is case-insensitivefont
- the Font to usepublic BufferedImage getImage()
Graph.draw(org.faceless.graph2.Output)
method.
Note that if this ImageOutput
was created by calling the
ImageOutput(Graphics2D,int,int)
constructor, this
method will return null
.
public BufferedImage getReducedColorImage(int numcolors, Color mask)
Return the Image created by the Graph.draw(org.faceless.graph2.Output)
method, after
it's been reduced to the specified number of colors. This is useful
for saving to bitmap formats like GIF and 8-bit PNG. The color-reduction
algorithm is fairly timeconsuming.
Note that if this ImageOutput
was created by calling the
ImageOutput(Graphics2D,int,int)
constructor, this
method will return null.
numcolors
- the number of colors to reduce the image to - must
be a power of two between 2 and 256mask
- the Color to mask transparent colors against during the
color reduction. Generally this is the background color you intend to
display the graph on, but it may be null
for no masking.public void writePNG(OutputStream out, int numcolors) throws IOException
OutputStream
.
Calls writePNG(out, numcolors, 0)
.
IOException
public void writePNG(OutputStream out, int numcolors, int dpi) throws IOException
OutputStream
.
If a partially transparent background color was used and numcolors
is
not zero, the background color will be changed to to fully transparent in order to
display correctly in Internet Explorer (which has broken PNG alpha support).
Note that if this ImageOutput
was created by calling the
ImageOutput(Graphics2D,int,int)
constructor, this method will
throw an IllegalStateException
out
- the OutputStream to write tonumcolors
- the number of colors to reduce the image to. This may be 0, to write
a full 24-bit RGB image, or a power of 2 between 2 and 256 to write an 8-bit indexed
image (which gives a smaller file but is more time-consuming to produce).dpi
- The DPI of the image, or 0 for unspecified. This has
no effect on the size of the image created: it simply writes a chunk to the
PNG which states the intended resolution of the image, which may be helpful in some
workflows.
IOException
Graph.setMetaData()
public Map getAreas()
Map
containing information about the areas used in the graph.
This can be used to create rollover or clickable areas on the resulting image.
The returned map has a String as a key and an Area
or GeneralPath
as a value. The key determines which object is being described, and is in one of
the following formats:
graph.series.name |
Represents the Area used by the actual series, where name is one (or more)
fields describing the actual data, separated by dots. For instance, if you created
a series like this:
BarSeries s = new BarSeries("myseries"); s.set("Apples", 20); s.set("Oranges", 20);Then this Map would include at least the two keys graph.series.myseries.Apples
and graph.series.myseries.Oranges . For stacked bars, you might get
graph.series.myseries.2001.Apples , and for LineGraphs, where there is no real
division of the data, you would simply get graph.series.myseries .
|
---|---|
trace.graph.series.name |
This is a GeneralPath object representing the course actually taken by the data,
which may be different the the value returned by graph.series.name if,
for instance, the graph is drawn with a linethickness > 1 or is rotated in 3D.
|
graph.marker.name |
Represents the Area used by a Marker on the graph. Here series is the
series the marker was added to, and name is the name of the marker. If no name
was specified for the marker (the default) then no entry will be added to the Map.
|
key.frame |
Represents the Area used by the Key box.
|
null
if
storeAreas
(true) wasn't called before drawing.public void storeAreas(boolean store)
getAreas()
method for more
information.
store
- whether to store information required by the getAreas()
method.getAreas()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |