Graphics2D

Extends
Graphics
Methods
21
Fields
None

Getting one

BufferedImage.new(…):createGraphics()
BufferedImage.new(…):getGraphics()

Methods

MethodReturnsDescription
setStroke(BasicStroke)()Sets the stroke draw and the line primitives use.
getStroke()BasicStrokeThe current stroke.
setComposite(AlphaComposite)()Sets the composite (AlphaComposite: a rule and an extra alpha).
getComposite()AlphaCompositeThe current composite.
setPaint(Color?)()(Graphics2D, Color?) -> (): Paints with a colour (as setColor); nil is ignored.
setPaint(Paint)()
setBackground(Color)()Sets the background colour clearRect fills with.
getBackground()ColorThe background colour.
setRenderingHint(RenderingHintsKey, any)()Sets one rendering hint. Antialiasing, text antialiasing, stroke control and interpolation change how later draws rasterize; the rest are s…
getRenderingHint(RenderingHintsKey)number?The value of one rendering hint (its default where none was set; nil for an interpolation hint never set).
translate(number, number)()(Graphics2D, number, number) -> (): Translates the origin by whole pixels.
rotate(number)()(Graphics2D, number) -> (): Rotates by theta radians about the origin.
rotate(number, number, number)()
scale(number, number)()Scales.
shear(number, number)()Shears.
transform(AffineTransform)()Concatenates tx to the transform.
setTransform(AffineTransform)()Replaces the transform.
getTransform()AffineTransformA copy of the transform.
clip(Shape)()Intersects the clip with shape (user space).
draw(Shape)()Strokes shape with the current stroke.
fill(Shape)()Fills shape (its winding rule).
drawString(string, number, number)()(Graphics2D, string, number, number) -> (): Draws s with its baseline at y and its left edge at x, in the current font and colour, with…
drawImage(Image?, number, number, ImageObserver?)boolean(Graphics2D, Image?, number, number, ImageObserver?) -> boolean: Draws img with its top-left at (x, y). true, as for any loaded image.
drawImage(Image?, number, number, number, number, ImageObserver?)boolean
drawImage(Image?, number, number, number, number, number, number, number, number, ImageObserver?)boolean
drawImage(Image?, AffineTransform, ImageObserver?)boolean

Returned by

MethodReturnsDescription
BufferedImage.createGraphicsGraphics2DA Graphics2D drawing into this image: each call draws at once. Dispose it when done (nothing leaks if not).
BufferedImage.getGraphicsGraphics2DThe same as createGraphics().
Graphics.createGraphics2D(Graphics) -> Graphics2D: A new graphics object with a copy of this one's state.

Method details

setPaint

setPaint: ((Graphics2D, Color?) -> ()) & ((Graphics2D, Paint) -> ())

(Graphics2D, Color?) -> (): Paints with a colour (as setColor); nil is ignored.

(Graphics2D, Paint) -> (): Paints with a two-colour gradient. getColor keeps the last colour.

setRenderingHint

setRenderingHint: (Graphics2D, RenderingHintsKey, any) -> ()

Sets one rendering hint. Antialiasing, text antialiasing, stroke control and interpolation change how later draws rasterize; the rest are stored and answered. A value of another key raises.

translate

translate: (Graphics2D, number, number) -> ()

(Graphics2D, number, number) -> (): Translates the origin by whole pixels.

(Graphics2D, number, number) -> (): Translates the origin.

rotate

rotate: ((Graphics2D, number) -> ()) & ((Graphics2D, number, number, number) -> ())

(Graphics2D, number) -> (): Rotates by theta radians about the origin.

(Graphics2D, number, number, number) -> (): Rotates by theta radians about (x, y).

drawString

drawString: (Graphics2D, string, number, number) -> ()

(Graphics2D, string, number, number) -> (): Draws s with its baseline at y and its left edge at x, in the current font and colour, with no shadow.

(Graphics2D, string, number, number) -> (): drawString at a fractional position.

drawImage

drawImage: ((Graphics2D, Image?, number, number, ImageObserver?) -> boolean) & ((Graphics2D, Image?, number, number, number, number, ImageObserver?) -> boolean) & ((Graphics2D, Image?, number, number, number, number, number, number, number, number, ImageObserver?) -> boolean) & ((Graphics2D, Image?, AffineTransform, ImageObserver?) -> boolean)

(Graphics2D, Image?, number, number, ImageObserver?) -> boolean: Draws img with its top-left at (x, y). true, as for any loaded image.

(Graphics2D, Image?, number, number, number, number, ImageObserver?) -> boolean: Draws img scaled into the rectangle.

(Graphics2D, Image?, number, number, number, number, number, number, number, number, ImageObserver?) -> boolean: Draws the source rectangle (sx1, sy1)-(sx2, sy2) of img into the destination rectangle (dx1, dy1)-(dx2, dy2), flipping where the corners are reversed.

(Graphics2D, Image?, AffineTransform, ImageObserver?) -> boolean: Draws img through xform (after the current transform).