public final class SVGGraphics2D extends Graphics2D
A Graphics2D implementation that creates SVG output. After
rendering the graphics via the SVGGraphics2D, you can retrieve
an SVG element (see getSVGElement()) or an SVG document (see
getSVGDocument()) containing your content.
Using the SVGGraphics2D class is straightforward. First,
create an instance specifying the height and width of the SVG element that
will be created. Then, use standard Java2D API calls to draw content
into the element. Finally, retrieve the SVG element that has been
accumulated. For example:
SVGGraphics2D g2 = new SVGGraphics2D(300, 200);
g2.setPaint(Color.RED);
g2.draw(new Rectangle(10, 10, 280, 180);
String svgElement = g2.getSVGElement();
For the content generation step, you can make use of third party libraries, such as JFreeChart and Orson Charts, that render output using standard Java2D API calls.
Rendering Hints
The SVGGraphics2D supports a couple of custom rendering hints -
for details, refer to the SVGHints class documentation. Also see
the examples in this blog post:
Orson Charts 3D / Enhanced SVG Export.
ImageObserver
parameter note that the observer is ignored completely. In any case, using
images that are not fully loaded already would not be a good idea in the
context of generating SVG data/files;getFontMetrics(java.awt.Font) and
getFontRenderContext() methods return values that come from an
internal BufferedImage, this is a short-cut and we don't know
if there are any negative consequences (if you know of any, please let us
know and we'll add the info here or find a way to fix it);defsKeyPrefix attribute to help ensure that unique IDs are
generated.
For some demos showing how to use this class, look in the
org.jfree.graphics2d.demo package in the src directory.
| Constructor and Description |
|---|
SVGGraphics2D(int width,
int height)
Creates a new instance with the specified width and height.
|
SVGGraphics2D(int width,
int height,
StringBuilder sb)
Creates a new instance with the specified width and height that will
populate the supplied StringBuilder instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRenderingHints(Map<?,?> hints)
Adds all the supplied rendering hints.
|
void |
clearRect(int x,
int y,
int width,
int height)
Clears the specified rectangle by filling it with the current
background color.
|
void |
clip(Shape s)
Clips to the intersection of the current clipping region and the
specified shape.
|
void |
clipRect(int x,
int y,
int width,
int height)
Clips to the intersection of the current clipping region and the
specified rectangle.
|
void |
copyArea(int x,
int y,
int width,
int height,
int dx,
int dy)
This method does nothing.
|
Graphics |
create()
Creates a new graphics object that is a copy of this graphics object
(except that it has not accumulated the drawing operations).
|
void |
dispose()
This method does nothing, there are no resources to dispose.
|
void |
draw(Shape s)
Draws the specified shape with the current
paint and
stroke. |
void |
drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Draws an arc contained within the rectangle
(x, y, width, height), starting at startAngle
and continuing through arcAngle degrees using
the current paint and stroke. |
void |
drawGlyphVector(GlyphVector g,
float x,
float y)
Draws the specified glyph vector at the location
(x, y). |
void |
drawImage(BufferedImage img,
BufferedImageOp op,
int x,
int y)
Draws the image resulting from applying the
BufferedImageOp
to the specified image at the location (x, y). |
boolean |
drawImage(Image img,
AffineTransform xform,
ImageObserver obs)
Draws an image with the specified transform.
|
boolean |
drawImage(Image img,
int x,
int y,
Color bgcolor,
ImageObserver observer)
Draws an image at the location
(x, y). |
boolean |
drawImage(Image img,
int x,
int y,
ImageObserver observer)
Draws an image at the location
(x, y). |
boolean |
drawImage(Image img,
int x,
int y,
int w,
int h,
Color bgcolor,
ImageObserver observer)
Draws an image to the rectangle
(x, y, w, h) (scaling it if
required), first filling the background with the specified color. |
boolean |
drawImage(Image img,
int x,
int y,
int w,
int h,
ImageObserver observer)
Draws the image into the rectangle defined by
(x, y, w, h). |
boolean |
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
Color bgcolor,
ImageObserver observer)
Draws part of an image (defined by the source rectangle
(sx1, sy1, sx2, sy2)) into the destination rectangle
(dx1, dy1, dx2, dy2). |
boolean |
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
ImageObserver observer)
Draws part of an image (defined by the source rectangle
(sx1, sy1, sx2, sy2)) into the destination rectangle
(dx1, dy1, dx2, dy2). |
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line from
(x1, y1) to (x2, y2) using
the current paint and stroke. |
void |
drawOval(int x,
int y,
int width,
int height)
Draws an oval framed by the rectangle
(x, y, width, height)
using the current paint and stroke. |
void |
drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Draws the specified polygon using the current
paint and
stroke. |
void |
drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
Draws the specified multi-segment line using the current
paint and stroke. |
void |
drawRenderableImage(RenderableImage img,
AffineTransform xform)
Draws the renderable image.
|
void |
drawRenderedImage(RenderedImage img,
AffineTransform xform)
Draws the rendered image.
|
void |
drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draws a rectangle with rounded corners using the current
paint and stroke. |
void |
drawString(AttributedCharacterIterator iterator,
float x,
float y)
Draws a string of attributed characters at
(x, y). |
void |
drawString(AttributedCharacterIterator iterator,
int x,
int y)
Draws a string of attributed characters at
(x, y). |
void |
drawString(String str,
float x,
float y)
Draws a string at
(x, y). |
void |
drawString(String str,
int x,
int y)
Draws a string at
(x, y). |
void |
fill(Shape s)
Fills the specified shape with the current
paint. |
void |
fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Fills an arc contained within the rectangle
(x, y, width, height), starting at startAngle
and continuing through arcAngle degrees, using
the current paint. |
void |
fillOval(int x,
int y,
int width,
int height)
Fills an oval framed by the rectangle
(x, y, width, height). |
void |
fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Fills the specified polygon using the current
paint. |
void |
fillRect(int x,
int y,
int width,
int height)
Fills the specified rectangle with the current
paint. |
void |
fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Fills a rectangle with rounded corners using the current
paint. |
Color |
getBackground()
Returns the background color.
|
boolean |
getCheckStrokeControlHint()
Returns the flag that controls whether or not this object will observe
the
KEY_STROKE_CONTROL rendering hint. |
Shape |
getClip()
Returns the user clipping region.
|
Rectangle |
getClipBounds()
Returns the bounds of the user clipping region.
|
Color |
getColor()
Returns the foreground color.
|
Composite |
getComposite()
Returns the current composite.
|
String |
getDefsKeyPrefix()
Returns the prefix used for all keys in the DEFS element.
|
GraphicsConfiguration |
getDeviceConfiguration()
Returns the device configuration associated with this
Graphics2D. |
Set<String> |
getElementIDs()
Returns a new set containing the element IDs that have been used in
output so far.
|
String |
getFilePrefix()
Returns the prefix used to generate a filename for an image that is
referenced from, rather than embedded in, the SVG element.
|
String |
getFileSuffix()
Returns the suffix used to generate a filename for an image that is
referenced from, rather than embedded in, the SVG element.
|
Font |
getFont()
Returns the current font used for drawing text.
|
FontMapper |
getFontMapper()
Returns the font mapper (an object that optionally maps font family
names to alternates).
|
FontMetrics |
getFontMetrics(Font f)
Returns the font metrics for the specified font.
|
FontRenderContext |
getFontRenderContext()
Returns the font render context.
|
int |
getGeometryDP()
Returns the number of decimal places used to write the coordinates
of geometrical shapes.
|
int |
getHeight()
Returns the height for the SVG element, specified in the constructor.
|
Paint |
getPaint()
Returns the paint used to draw or fill shapes (or text).
|
Object |
getRenderingHint(RenderingHints.Key hintKey)
Returns the current value for the specified hint.
|
RenderingHints |
getRenderingHints()
Returns a copy of the rendering hints.
|
String |
getShapeRendering()
Returns the value of the 'shape-rendering' property that will be
written to the SVG element.
|
Stroke |
getStroke()
Returns the current stroke (used when drawing shapes).
|
String |
getSVGDocument()
Returns an SVG document (this contains the content returned by the
getSVGElement() method, prepended with the required document
header). |
String |
getSVGElement()
Returns the SVG element that has been generated by calls to this
Graphics2D implementation. |
String |
getSVGElement(String id)
Returns the SVG element that has been generated by calls to this
Graphics2D implementation, giving it the specified id. |
List<ImageElement> |
getSVGImages()
Returns the list of image elements that have been referenced in the
SVG output but not embedded.
|
String |
getTextRendering()
Returns the value of the 'text-rendering' property that will be
written to the SVG element.
|
AffineTransform |
getTransform()
Returns a copy of the current transform.
|
int |
getTransformDP()
Returns the number of decimal places used to write the transformation
matrices in the SVG output.
|
int |
getWidth()
Returns the width for the SVG element, specified in the constructor.
|
double |
getZeroStrokeWidth()
Returns the width to use for the SVG stroke when the AWT stroke
specified has a zero width (the default value is
0.1). |
boolean |
hit(Rectangle rect,
Shape s,
boolean onStroke)
Returns
true if the rectangle (in device space) intersects
with the shape (the interior, if onStroke is false,
otherwise the stroked outline of the shape). |
void |
rotate(double theta)
Applies a rotation (anti-clockwise) about
(0, 0). |
void |
rotate(double theta,
double x,
double y)
Applies a rotation (anti-clockwise) about
(x, y). |
void |
scale(double sx,
double sy)
Applies a scale transformation.
|
void |
setBackground(Color color)
Sets the background color.
|
void |
setCheckStrokeControlHint(boolean check)
Sets the flag that controls whether or not this object will observe
the
KEY_STROKE_CONTROL rendering hint. |
void |
setClip(int x,
int y,
int width,
int height)
Sets the user clipping region to the specified rectangle.
|
void |
setClip(Shape shape)
Sets the user clipping region.
|
void |
setColor(Color c)
Sets the foreground color.
|
void |
setComposite(Composite comp)
Sets the composite (only
AlphaComposite is handled). |
void |
setDefsKeyPrefix(String prefix)
Sets the prefix that will be used for all keys in the DEFS element.
|
void |
setFilePrefix(String prefix)
Sets the prefix used to generate a filename for any image that is
referenced from the SVG element.
|
void |
setFileSuffix(String suffix)
Sets the suffix used to generate a filename for any image that is
referenced from the SVG element.
|
void |
setFont(Font font)
Sets the font to be used for drawing text.
|
void |
setFontMapper(FontMapper mapper)
Sets the font mapper.
|
void |
setGeometryDP(int dp)
Sets the number of decimal places used to write the coordinates of
geometrical shapes in the SVG output.
|
void |
setPaint(Paint paint)
Sets the paint used to draw or fill shapes (or text).
|
void |
setPaintMode()
Does nothing in this
SVGGraphics2D implementation. |
void |
setRenderingHint(RenderingHints.Key hintKey,
Object hintValue)
Sets the value for a hint.
|
void |
setRenderingHints(Map<?,?> hints)
Sets the rendering hints to the specified collection.
|
void |
setShapeRendering(String value)
Sets the value of the 'shape-rendering' property that will be written to
the SVG element.
|
void |
setStroke(Stroke s)
Sets the stroke that will be used to draw shapes.
|
void |
setTextRendering(String value)
Sets the value of the 'text-rendering' property that will be written to
the SVG element.
|
void |
setTransform(AffineTransform t)
Sets the transform.
|
void |
setTransformDP(int dp)
Sets the number of decimal places used to write the transformation
matrices in the SVG output.
|
void |
setXORMode(Color c)
Does nothing in this
SVGGraphics2D implementation. |
void |
setZeroStrokeWidth(double width)
Sets the width to use for the SVG stroke when the current AWT stroke
has a width of 0.0.
|
void |
shear(double shx,
double shy)
Applies a shear transformation.
|
void |
transform(AffineTransform t)
Applies this transform to the existing transform by concatenating it.
|
void |
translate(double tx,
double ty)
Applies the translation
(tx, ty). |
void |
translate(int tx,
int ty)
Applies the translation
(tx, ty). |
draw3DRect, fill3DRectcreate, drawBytes, drawChars, drawPolygon, drawRect, fillPolygon, finalize, getClipBounds, getClipRect, getFontMetrics, hitClip, toStringpublic SVGGraphics2D(int width,
int height)
width - the width of the SVG element.height - the height of the SVG element.public SVGGraphics2D(int width,
int height,
StringBuilder sb)
create() method, but won't normally be called
directly by user code.width - the width of the SVG element.height - the height of the SVG element.sb - the string builder (null not permitted).public int getWidth()
getSVGElement() method.public int getHeight()
getSVGElement() method.public String getShapeRendering()
public void setShapeRendering(String value)
value - the new value.public String getTextRendering()
public void setTextRendering(String value)
value - the new value.public boolean getCheckStrokeControlHint()
KEY_STROKE_CONTROL rendering hint. The default value is
true.setCheckStrokeControlHint(boolean)public void setCheckStrokeControlHint(boolean check)
KEY_STROKE_CONTROL rendering hint. When enabled (the
default), a hint to normalise strokes will write a stroke-style
attribute with the value crispEdges.check - the new flag value.getCheckStrokeControlHint()public String getDefsKeyPrefix()
String.valueOf(System.nanoTime()).null).public void setDefsKeyPrefix(String prefix)
prefix - the prefix (null not permitted).public int getTransformDP()
Note that there is a separate attribute to control the number of decimal
places for geometrical elements in the output (see
getGeometryDP()).
setTransformDP(int)public void setTransformDP(int dp)
String conversion of
double primitives (approximately 16 decimals places).
Note that there is a separate attribute to control the number of decimal
places for geometrical elements in the output (see
setGeometryDP(int)).
dp - the number of decimal places (normally 1 to 10).getTransformDP()public int getGeometryDP()
Note that there is a separate attribute to control the number of decimal
places for transform matrices in the output (see
getTransformDP()).
public void setGeometryDP(int dp)
Note that there is a separate attribute to control the number of decimal
places for transform matrices in the output (see
setTransformDP(int)).
dp - the number of decimal places (normally 1 to 10).public String getFilePrefix()
null).public void setFilePrefix(String prefix)
prefix - the new prefix (null not permitted).public String getFileSuffix()
null).public void setFileSuffix(String suffix)
suffix - the new prefix (null not permitted).public double getZeroStrokeWidth()
0.1). In
the Java specification for BasicStroke it states "If width
is set to 0.0f, the stroke is rendered as the thinnest possible
line for the target device and the antialias hint setting." We don't
have a means to implement that accurately since we must specify a fixed
width.public void setZeroStrokeWidth(double width)
width - the new width (must be 0 or greater).public GraphicsConfiguration getDeviceConfiguration()
Graphics2D.getDeviceConfiguration in class Graphics2Dpublic Graphics create()
public Paint getPaint()
Color.BLACK.getPaint in class Graphics2Dnull).setPaint(java.awt.Paint)public void setPaint(Paint paint)
paint is an instance of Color, this method will
also update the current color attribute (see getColor()). If
you pass null to this method, it does nothing (in
accordance with the JDK specification).setPaint in class Graphics2Dpaint - the paint (null is permitted but ignored).getPaint()public Color getColor()
getPaint() method.getColor in class Graphicsnull).getPaint()public void setColor(Color c)
setPaint(java.awt.Paint) method.setColor in class Graphicsc - the color (null permitted but ignored).setPaint(java.awt.Paint)public Color getBackground()
Color.BLACK.
This is used by the clearRect(int, int, int, int) method.getBackground in class Graphics2Dnull).setBackground(java.awt.Color)public void setBackground(Color color)
clearRect(int, int, int, int) method. The reference
implementation allows null for the background color so
we allow that too (but for that case, the clearRect method will do
nothing).setBackground in class Graphics2Dcolor - the color (null permitted).getBackground()public Composite getComposite()
getComposite in class Graphics2Dnull).setComposite(java.awt.Composite)public void setComposite(Composite comp)
AlphaComposite is handled).setComposite in class Graphics2Dcomp - the composite (null not permitted).getComposite()public Stroke getStroke()
getStroke in class Graphics2Dnull).setStroke(java.awt.Stroke)public void setStroke(Stroke s)
setStroke in class Graphics2Ds - the stroke (null not permitted).getStroke()public Object getRenderingHint(RenderingHints.Key hintKey)
SVGHints class for information about the hints that can be
used with SVGGraphics2D.getRenderingHint in class Graphics2DhintKey - the hint key (null permitted, but the
result will be null also).null).setRenderingHint(java.awt.RenderingHints.Key, java.lang.Object)public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
SVGHints class for
information about the hints that can be used with this implementation.setRenderingHint in class Graphics2DhintKey - the hint key (null not permitted).hintValue - the hint value.getRenderingHint(java.awt.RenderingHints.Key)public RenderingHints getRenderingHints()
Graphics2D instance.getRenderingHints in class Graphics2Dnull).setRenderingHints(java.util.Map)public void setRenderingHints(Map<?,?> hints)
setRenderingHints in class Graphics2Dhints - the new set of hints (null not permitted).getRenderingHints()public void addRenderingHints(Map<?,?> hints)
addRenderingHints in class Graphics2Dhints - the hints (null not permitted).public void draw(Shape s)
paint and
stroke. There is direct handling for Line2D,
Rectangle2D, Ellipse2D and Path2D. All other
shapes are mapped to a GeneralPath and then drawn (effectively
as Path2D objects).draw in class Graphics2Ds - the shape (null not permitted).fill(java.awt.Shape)public void fill(Shape s)
paint. There is
direct handling for Rectangle2D, Ellipse2D and
Path2D. All other shapes are mapped to a GeneralPath
and then filled.fill in class Graphics2Ds - the shape (null not permitted).draw(java.awt.Shape)public Font getFont()
getFont in class Graphicsnull).setFont(java.awt.Font)public void setFont(Font font)
public FontMapper getFontMapper()
null).setFontMapper(org.jfree.graphics2d.svg.FontMapper)public void setFontMapper(FontMapper mapper)
mapper - the font mapper (null not permitted).public FontMetrics getFontMetrics(Font f)
getFontMetrics in class Graphicsf - the font.public FontRenderContext getFontRenderContext()
getFontRenderContext in class Graphics2Dnull).public void drawString(String str, int x, int y)
(x, y). The start of the text at the
baseline level will be aligned with the (x, y) point.
SVGHints.KEY_TEXT_RENDERING
hint when drawing strings (this is completely optional though).drawString in class Graphics2Dstr - the string (null not permitted).x - the x-coordinate.y - the y-coordinate.drawString(java.lang.String, float, float)public void drawString(String str, float x, float y)
(x, y). The start of the text at the
baseline level will be aligned with the (x, y) point.
SVGHints.KEY_TEXT_RENDERING
hint when drawing strings (this is completely optional though).drawString in class Graphics2Dstr - the string (null not permitted).x - the x-coordinate.y - the y-coordinate.public void drawString(AttributedCharacterIterator iterator, int x, int y)
(x, y). The
call is delegated to
drawString(AttributedCharacterIterator, float, float).drawString in class Graphics2Diterator - an iterator for the characters.x - the x-coordinate.y - the x-coordinate.public void drawString(AttributedCharacterIterator iterator, float x, float y)
(x, y).drawString in class Graphics2Diterator - an iterator over the characters (null not
permitted).x - the x-coordinate.y - the y-coordinate.public void drawGlyphVector(GlyphVector g, float x, float y)
(x, y).drawGlyphVector in class Graphics2Dg - the glyph vector (null not permitted).x - the x-coordinate.y - the y-coordinate.public void translate(int tx,
int ty)
(tx, ty). This call is delegated
to translate(double, double).translate in class Graphics2Dtx - the x-translation.ty - the y-translation.translate(double, double)public void translate(double tx,
double ty)
(tx, ty).translate in class Graphics2Dtx - the x-translation.ty - the y-translation.public void rotate(double theta)
(0, 0).rotate in class Graphics2Dtheta - the rotation angle (in radians).public void rotate(double theta,
double x,
double y)
(x, y).rotate in class Graphics2Dtheta - the rotation angle (in radians).x - the x-coordinate.y - the y-coordinate.public void scale(double sx,
double sy)
scale in class Graphics2Dsx - the x-scaling factor.sy - the y-scaling factor.public void shear(double shx,
double shy)
transform method:
transform(AffineTransform.getShearInstance(shx, shy));
shear in class Graphics2Dshx - the x-shear factor.shy - the y-shear factor.public void transform(AffineTransform t)
transform in class Graphics2Dt - the transform (null not permitted).public AffineTransform getTransform()
getTransform in class Graphics2Dnull).setTransform(java.awt.geom.AffineTransform)public void setTransform(AffineTransform t)
setTransform in class Graphics2Dt - the new transform (null permitted, resets to the
identity transform).getTransform()public boolean hit(Rectangle rect, Shape s, boolean onStroke)
true if the rectangle (in device space) intersects
with the shape (the interior, if onStroke is false,
otherwise the stroked outline of the shape).hit in class Graphics2Drect - a rectangle (in device space).s - the shape.onStroke - test the stroked outline only?public void setPaintMode()
SVGGraphics2D implementation.setPaintMode in class Graphicspublic void setXORMode(Color c)
SVGGraphics2D implementation.setXORMode in class Graphicsc - ignoredpublic Rectangle getClipBounds()
getClipBounds in class Graphicsnull).getClip()public Shape getClip()
null.getClip in class Graphicsnull).setClip(java.awt.Shape)public void setClip(Shape shape)
public void clip(Shape s)
null argument, but there is an open bug report (since 2004)
that suggests this is wrong:
clip in class Graphics2Ds - the clip shape (null not permitted).public void clipRect(int x,
int y,
int width,
int height)
public void setClip(int x,
int y,
int width,
int height)
public void drawLine(int x1,
int y1,
int x2,
int y2)
(x1, y1) to (x2, y2) using
the current paint and stroke.public void fillRect(int x,
int y,
int width,
int height)
paint.public void clearRect(int x,
int y,
int width,
int height)
null, this
method will do nothing.clearRect in class Graphicsx - the x-coordinate.y - the y-coordinate.width - the width.height - the height.getBackground()public void drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
paint and stroke.drawRoundRect in class Graphicsx - the x-coordinate.y - the y-coordinate.width - the width.height - the height.arcWidth - the arc-width.arcHeight - the arc-height.fillRoundRect(int, int, int, int, int, int)public void fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
paint.fillRoundRect in class Graphicsx - the x-coordinate.y - the y-coordinate.width - the width.height - the height.arcWidth - the arc-width.arcHeight - the arc-height.drawRoundRect(int, int, int, int, int, int)public void drawOval(int x,
int y,
int width,
int height)
(x, y, width, height)
using the current paint and stroke.drawOval in class Graphicsx - the x-coordinate.y - the y-coordinate.width - the width.height - the height.fillOval(int, int, int, int)public void fillOval(int x,
int y,
int width,
int height)
(x, y, width, height).fillOval in class Graphicsx - the x-coordinate.y - the y-coordinate.width - the width.height - the height.drawOval(int, int, int, int)public void drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
(x, y, width, height), starting at startAngle
and continuing through arcAngle degrees using
the current paint and stroke.drawArc in class Graphicsx - the x-coordinate.y - the y-coordinate.width - the width.height - the height.startAngle - the start angle in degrees, 0 = 3 o'clock.arcAngle - the angle (anticlockwise) in degrees.fillArc(int, int, int, int, int, int)public void fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
(x, y, width, height), starting at startAngle
and continuing through arcAngle degrees, using
the current paint.fillArc in class Graphicsx - the x-coordinate.y - the y-coordinate.width - the width.height - the height.startAngle - the start angle in degrees, 0 = 3 o'clock.arcAngle - the angle (anticlockwise) in degrees.drawArc(int, int, int, int, int, int)public void drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
paint and stroke.drawPolyline in class GraphicsxPoints - the x-points.yPoints - the y-points.nPoints - the number of points to use for the polyline.public void drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
paint and
stroke.drawPolygon in class GraphicsxPoints - the x-points.yPoints - the y-points.nPoints - the number of points to use for the polygon.fillPolygon(int[], int[], int)public void fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
paint.fillPolygon in class GraphicsxPoints - the x-points.yPoints - the y-points.nPoints - the number of points to use for the polygon.drawPolygon(int[], int[], int)public boolean drawImage(Image img, int x, int y, ImageObserver observer)
(x, y). Note that the
observer is ignored.public boolean drawImage(Image img, int x, int y, int w, int h, ImageObserver observer)
(x, y, w, h).
Note that the observer is ignored (it is not useful in this
context).public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
(x, y). Note that the
observer is ignored.public boolean drawImage(Image img, int x, int y, int w, int h, Color bgcolor, ImageObserver observer)
(x, y, w, h) (scaling it if
required), first filling the background with the specified color. Note
that the observer is ignored.public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
(sx1, sy1, sx2, sy2)) into the destination rectangle
(dx1, dy1, dx2, dy2). Note that the observer is ignored.drawImage in class Graphicsimg - the image.dx1 - the x-coordinate for the top left of the destination.dy1 - the y-coordinate for the top left of the destination.dx2 - the x-coordinate for the bottom right of the destination.dy2 - the y-coordinate for the bottom right of the destination.sx1 - the x-coordinate for the top left of the source.sy1 - the y-coordinate for the top left of the source.sx2 - the x-coordinate for the bottom right of the source.sy2 - the y-coordinate for the bottom right of the source.true if the image is drawn.public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
(sx1, sy1, sx2, sy2)) into the destination rectangle
(dx1, dy1, dx2, dy2). The destination rectangle is first
cleared by filling it with the specified bgcolor. Note that
the observer is ignored.drawImage in class Graphicsimg - the image.dx1 - the x-coordinate for the top left of the destination.dy1 - the y-coordinate for the top left of the destination.dx2 - the x-coordinate for the bottom right of the destination.dy2 - the y-coordinate for the bottom right of the destination.sx1 - the x-coordinate for the top left of the source.sy1 - the y-coordinate for the top left of the source.sx2 - the x-coordinate for the bottom right of the source.sy2 - the y-coordinate for the bottom right of the source.bgcolor - the background color (null permitted).observer - ignored.true if the image is drawn.public void drawRenderedImage(RenderedImage img, AffineTransform xform)
drawRenderedImage in class Graphics2Dimg - the image.xform - the transform.public void drawRenderableImage(RenderableImage img, AffineTransform xform)
drawRenderableImage in class Graphics2Dimg - the renderable image.xform - the transform.public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)
observer is ignored.drawImage in class Graphics2Dimg - the image.xform - the transform.obs - the image observer (ignored).true if the image is drawn.public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y)
BufferedImageOp
to the specified image at the location (x, y).drawImage in class Graphics2Dimg - the image.op - the operation.x - the x-coordinate.y - the y-coordinate.public void copyArea(int x,
int y,
int width,
int height,
int dx,
int dy)
public void dispose()
public String getSVGElement()
Graphics2D implementation.public String getSVGElement(String id)
Graphics2D implementation, giving it the specified id.
If id is null, the element will have no id
attribute.id - the element id (null permitted).public String getSVGDocument()
getSVGElement() method, prepended with the required document
header).public List<ImageElement> getSVGImages()
SVGHints.KEY_IMAGE_HANDLINGCopyright © 2016. All rights reserved.