public class GGBitmap
extends java.lang.Object
Constructor and Description |
---|
GGBitmap(int width,
int height)
Creates a GGBitmap with given number of horizontal and vertical pixels
that holds a Bitmap instance to draw graphics elements.
|
GGBitmap(int width,
int height,
java.awt.Color bgColor)
Creates a GGBitmap with given number of horizontal and vertical pixels
that holds a Bitmap instance to draw graphics elements.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the bitmap by painting it with the current background color.
|
void |
clear(java.awt.Color color)
Clears the bitmap by painting it with the given background color.
|
void |
dispose()
Releases all resources of the graphics context.
|
void |
drawArc(java.awt.Point pt,
int radius,
double startAngle,
double extendAngle)
Draws an arc with given center, radius, start and end angle.
|
void |
drawCircle(java.awt.Point center,
int radius)
Draws a circle with given center and given radius.
|
void |
drawGeneralPath(java.awt.geom.GeneralPath gp)
Draws a figure defined by the given GeneralPath.
|
void |
drawImage(java.awt.image.BufferedImage bi)
Draws the given image at position (0, 0) into the bitmap.
|
void |
drawImage(java.awt.image.BufferedImage bi,
int x,
int y)
Draws the given image into the bitmap.
|
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line from one coordinate pair to another coordinate pair.
|
void |
drawLine(java.awt.Point pt1,
java.awt.Point pt2)
Draws a line from one coordinate pair to another coordinate pair.
|
void |
drawPoint(java.awt.Point pt)
Draws a single point.
|
void |
drawPolygon(java.awt.Point[] vertexes)
Draws a polygon with given vertexes.
|
void |
drawRectangle(java.awt.Point pt1,
java.awt.Point pt2)
Draws a rectangle with given opposite corners.
|
void |
drawText(java.lang.String text,
java.awt.Point pt)
Displays the given text at the given position using the current font.
|
void |
fillArc(java.awt.Point pt,
int radius,
double startAngle,
double extendAngle)
Fills an arc with given center, radius, start and end angle.
|
void |
fillCircle(java.awt.Point center,
int radius)
Draws a filled circle with given center and given radius.
|
void |
fillGeneralPath(java.awt.geom.GeneralPath gp)
Fills a figure defined by the given GeneralPath.
|
void |
fillPolygon(java.awt.Point[] vertexes)
Draws a filled polygon with given vertexes.
|
void |
fillRectangle(java.awt.Point pt1,
java.awt.Point pt2)
Draws a filled rectangle with given opposite corners.
|
static java.awt.image.BufferedImage |
floodFill(java.awt.image.BufferedImage bi,
java.awt.Point pt,
java.awt.Color oldColor,
java.awt.Color newColor)
Fills a bounded single-colored region with
the given color.
|
static java.lang.String[] |
getAvailableFontFamilies()
Returns the available font families for the current platform.
|
java.awt.Color |
getBgColor()
Returns the current background color.
|
java.awt.image.BufferedImage |
getBufferedImage()
Returns the reference of the buffered image used as bitmap.
|
static byte[] |
getByteArray(java.awt.image.BufferedImage sourceImage,
java.lang.String imageFormat)
Returns the image in a byte array. imageFormat is the informal name
of the format (one of the strings returned by get SupportedImageFormats()).
|
java.awt.Color |
getColor(java.awt.Point pt)
Returns the color of the pixel of the background at given point.
|
java.awt.Graphics2D |
getContext()
Returns the graphics device context used for drawing operations.
|
static java.awt.image.BufferedImage |
getImage(java.lang.String imagePath)
Retrieves the image either from the jar resource, from local drive or
from a internet server
From the given filename the image file is searched in the following order:
- if application is packed into a jar archive, relative to the root of the jar archive - relative to the directory <userhome>/gamegrid/ - relative or absolute to current application directory - if filename starts with http://, from the given URL - add prefix _ and search relative to the root of the jar archive |
int |
getLineWidth()
Returns the current line width in pixels.
|
java.awt.Color |
getPaintColor()
Returns the current paint color.
|
static java.awt.image.BufferedImage |
getScaledImage(java.awt.image.BufferedImage bi,
double factor,
double angle)
Transforms the given buffered image by scaling by the given factor and
rotating by the given angle.
|
static java.awt.image.BufferedImage |
getScaledImage(java.lang.String imagePath,
double factor,
double angle)
Retrieves the image either from the jar resource, from local drive or
from a internet server and transforms it by scaling it by the given
factor and rotating it by the given angle.
|
static java.lang.String[] |
getSupportedImageFormats()
Returns all supported image formats.
|
void |
setFont(java.awt.Font font)
Sets the font for displaying text with setText()
|
void |
setLineWidth(int width)
Sets the current line width in pixels.
|
void |
setPaintColor(java.awt.Color color)
Sets the given new paint color (for drawing and filling).
|
void |
setPaintMode()
Sets the paint mode of the graphics context to overwrite
with current paint color.
|
static java.awt.image.BufferedImage |
setTransparency(java.awt.image.BufferedImage bi,
double factor)
Returns a BufferedImage where each pixel has a new transparency value
(alpha component in the ARGB color model).
|
void |
setXORMode(java.awt.Color c)
Sets the paint mode to alternate between the current color and the given color.
|
static boolean |
writeImage(java.awt.image.BufferedImage bi,
java.lang.String filename,
java.lang.String type)
Writes a image file of the given BufferedImage.
|
public GGBitmap(int width, int height)
width
- the width of the Bitmap in pixelsheight
- the height of the Bitmap in pixelspublic GGBitmap(int width, int height, java.awt.Color bgColor)
width
- the width of the Bitmap in pixelsheight
- the height of the Bitmap in pixelsbgColor
- the color of the background, may be (semi-)transparentpublic static java.awt.image.BufferedImage getScaledImage(java.lang.String imagePath, double factor, double angle)
imagePath
- the file name or urlfactor
- the zoom factor (>1 zoom-in, <1 zoom-out)angle
- the rotation angle (in degrees clockwise)public static java.awt.image.BufferedImage getScaledImage(java.awt.image.BufferedImage bi, double factor, double angle)
bi
- the buffered image to transformfactor
- the zoom factor (>1 zoom-in, <1 zoom-out)angle
- the rotation angle (in degrees clockwise)public static java.awt.image.BufferedImage getImage(java.lang.String imagePath)
imagePath
- the file name or urlpublic void drawImage(java.awt.image.BufferedImage bi, int x, int y)
x
- x-coordinate of upper left cornery
- y-coordinate of upper left cornerpublic void drawImage(java.awt.image.BufferedImage bi)
public void clear(java.awt.Color color)
color
- the color of the backgroundpublic void clear()
public int getLineWidth()
public void setLineWidth(int width)
width
- the new line widthpublic java.awt.Color getPaintColor()
public void setPaintColor(java.awt.Color color)
color
- the new line colorpublic java.awt.Color getBgColor()
public void drawLine(int x1, int y1, int x2, int y2)
x1
- the x-coordinate of the start pointy1
- the y-coordinate of the start pointx2
- the x-coordinate of the endpointy2
- the y-coordinate of the endpointpublic void drawLine(java.awt.Point pt1, java.awt.Point pt2)
pt1
- the start pointpt2
- the endpointpublic void drawCircle(java.awt.Point center, int radius)
radius
- the radius of the circlepublic void fillCircle(java.awt.Point center, int radius)
center
- the center of the circleradius
- the radius of the circlepublic void drawRectangle(java.awt.Point pt1, java.awt.Point pt2)
pt1
- upper left vertex of the rectanglept2
- lower right vertex of the rectanglepublic void fillRectangle(java.awt.Point pt1, java.awt.Point pt2)
pt1
- upper left vertex of the rectanglept2
- lower right vertex of the rectanglepublic void drawArc(java.awt.Point pt, int radius, double startAngle, double extendAngle)
pt
- the center of the arcradius
- the radius of the arcstartAngle
- the start angle in degrees (zero to east, positive counterclockwise)extendAngle
- the extend angle in degrees (zero to east, positive counterclockwise)public void fillArc(java.awt.Point pt, int radius, double startAngle, double extendAngle)
pt
- the center of the arcradius
- the radius of the arcstartAngle
- the start angle in degrees (zero to east, positive counterclockwise)extendAngle
- the extendAngle in degrees (zero to east, positive counterclockwise)public void drawPolygon(java.awt.Point[] vertexes)
vertexes
- the vertexes of the polygonpublic void fillPolygon(java.awt.Point[] vertexes)
vertexes
- the vertexes of the polygonpublic void drawGeneralPath(java.awt.geom.GeneralPath gp)
gp
- the GeneralPath that defines the shapepublic void fillGeneralPath(java.awt.geom.GeneralPath gp)
gp
- the GeneralPath that defines the shapepublic void drawPoint(java.awt.Point pt)
pt
- the point to drawpublic java.awt.Color getColor(java.awt.Point pt)
pt
- point, where to pick the color; zero at upper left corner,
x to the left, y downwardspublic void setFont(java.awt.Font font)
font
- public void drawText(java.lang.String text, java.awt.Point pt)
text
- the text to displaypt
- the start point of the text baselinepublic static java.lang.String[] getAvailableFontFamilies()
public java.awt.Graphics2D getContext()
public java.awt.image.BufferedImage getBufferedImage()
public void setPaintMode()
public void setXORMode(java.awt.Color c)
public void dispose()
public static java.lang.String[] getSupportedImageFormats()
public static boolean writeImage(java.awt.image.BufferedImage bi, java.lang.String filename, java.lang.String type)
bi
- the given BufferedImage to copyfilename
- the path to the image filetype
- the image file format like "bmp", "gif", "jpg", "png" (all lowercase)public static java.awt.image.BufferedImage floodFill(java.awt.image.BufferedImage bi, java.awt.Point pt, java.awt.Color oldColor, java.awt.Color newColor)
bi
- the BufferedImage containing the connected regionpt
- a point inside the regionoldColor
- the old color of the regionnewColor
- the new color of the regionpublic static java.awt.image.BufferedImage setTransparency(java.awt.image.BufferedImage bi, double factor)
bi
- the original imagefactor
- the transparency multiplierpublic static byte[] getByteArray(java.awt.image.BufferedImage sourceImage, java.lang.String imageFormat)