public class Image extends SFMLNativeObject
| Modifier and Type | Class and Description |
|---|---|
static class |
Image.PixelOutOfBoundsException
Thrown if a non-existing pixel is being accessed by either
getPixel(int, int)
or setPixel(int, int, Color). |
| Constructor and Description |
|---|
Image()
Constructs a new empty image.
|
| Modifier and Type | Method and Description |
|---|---|
void |
copy(Image source,
int destX,
int destY)
Copies another image onto this image.
|
void |
copy(Image source,
int destX,
int destY,
IntRect sourceRect)
Copies a portion of another image onto this image.
|
void |
copy(Image source,
int destX,
int destY,
IntRect sourceRect,
boolean applyAlpha)
Copies a portion of another image onto this image.
|
void |
create(BufferedImage image)
Creates a new image by converting an AWT
BufferedImage. |
void |
create(int width,
int height)
Generates a new image and fills it with black.
|
void |
create(int width,
int height,
Color color)
Generates a new image and fills it with a color.
|
void |
create(int width,
int height,
int[] pixels)
Creates a new image from the given pixel data.
|
void |
createMaskFromColor(Color color)
Creates a transparency mask from the given color, making matching pixels fully transparent.
|
void |
createMaskFromColor(Color color,
int alpha)
Creates a transparency mask from the given color.
|
void |
flipHorizontally()
Flips the image horizontally.
|
void |
flipVertically()
Flips the image vertically.
|
Color |
getPixel(int x,
int y)
Gets the color of a certain pixel.
|
int[] |
getPixels()
Retrieves a copy of all the pixels of the image in 32-bit ARGB color format.
|
Vector2i |
getSize()
Gets the size of the image.
|
void |
loadFromFile(Path path)
Attempts to load an image from a file.
|
void |
loadFromStream(InputStream in)
Fully loads all available bytes from an
InputStream
and attempts to load the image from it. |
protected long |
nativeCreate()
Deprecated.
|
protected void |
nativeDelete()
Deprecated.
|
protected void |
nativeSetExPtr()
Deprecated.
|
void |
saveToFile(Path path)
Attempts to save the image to a file.
|
void |
setPixel(int x,
int y,
Color color)
Sets the color of a certain pixel.
|
BufferedImage |
toBufferedImage()
Converts this image to an AWT
BufferedImage. |
finalize@Deprecated protected long nativeCreate()
SFMLNativeObjectnativeCreate in class SFMLNativeObject@Deprecated protected void nativeSetExPtr()
SFMLNativeObjectnativeSetExPtr in class SFMLNativeObject@Deprecated protected void nativeDelete()
SFMLNativeObjectnativeDelete in class SFMLNativeObjectpublic void create(int width,
int height,
Color color)
width - the image's width.height - the image's height.color - the fill color of the image.public final void create(int width,
int height)
width - the image's width.height - the image's height.public void create(BufferedImage image)
BufferedImage.image - the AWT buffered image to convert.public void create(int width,
int height,
int[] pixels)
BufferedImage.TYPE_INT_ARGB
color format.width - the image's width.height - the image's height.pixels - the image's pixel data in 32-bit ARGB format.public void loadFromStream(InputStream in) throws IOException
InputStream
and attempts to load the image from it.in - the input stream to read from.IOException - in case an I/O error occurs.public void loadFromFile(Path path) throws IOException
path - the file to load the texture from.IOException - in case an I/O error occurs.public void saveToFile(Path path) throws IOException
path - the path to the file to write.IOException - in case an I/O error occurs.public Vector2i getSize()
public void createMaskFromColor(Color color, int alpha)
color - the color to be made transparent.alpha - the alpha value to assign to pixels matching the color key.public final void createMaskFromColor(Color color)
color - the color to be made transparent.public void copy(Image source, int destX, int destY, IntRect sourceRect, boolean applyAlpha)
source - the source image.destX - the destination X coordinate.destY - the destination X coordinate.sourceRect - the source rectangle. An empty rectangle means the full image.applyAlpha - true to copy alpha values as well, false to leave the destination alpha.public final void copy(Image source, int destX, int destY, IntRect sourceRect)
source - the source image.destX - the destination X coordinate.destY - the destination X coordinate.sourceRect - the source rectangle. An empty rectangle means the full image.public final void copy(Image source, int destX, int destY)
source - the source image.destX - the destination X coordinate.destY - the destination X coordinate.public void setPixel(int x,
int y,
Color color)
x - the pixel's X coordinate.y - the pixel's Y coordinate.color - the color to apply to the pixel.public Color getPixel(int x, int y)
x - the pixel's X coordinate.y - the pixel's Y coordinate.public int[] getPixels()
BufferedImage.TYPE_INT_ARGB
color format.public BufferedImage toBufferedImage()
BufferedImage.
The resulting buffered image will be of BufferedImage.TYPE_INT_ARGB
color format.public void flipHorizontally()
public void flipVertically()