Hi guys,
I use BufferedImages to display my sprites and animations in my game. It works really fine and now I want to make things “fancy”
On Stack Overflow did I found a way to manipulate an given image into a grayscale one. But how do I ink my images?
Given is a BufferedImage like this png:
[tr]
[td]given Image[/td]
[td]grayscaled[/td]
[td]inked[/td]
[/tr]
[tr]
[td]
[/td]
[td]
[/td]
[td]
[/td]
[/tr]
Red is just an example. I want to hand over a color and get the inked image as result.
My grayscale Code looks like this:
public static BufferedImage getGrayScaleImage(BufferedImage original) {
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
GraphicsConfiguration graphicsConfiguration = graphicsDevice.getDefaultConfiguration();
// If the source image has no alpha info use Transparency.OPAQUE instead
BufferedImage image = graphicsConfiguration.createCompatibleImage(original.getWidth(null), original.getHeight(null), Transparency.BITMASK);
// Copy image to buffered image
Graphics graphics = image.createGraphics();
// Paint the image onto the buffered image
graphics.drawImage(original, 0, 0, null);
graphics.dispose();
// Convert to grayscale
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp op = new ColorConvertOp(cs, null);
image = op.filter(image, null);
return image;
}
I haven’t used ColorSpace or ColorConvertOp ever, so I don’t how to use them ???
My second question is a bit more tricky. Like I said: I use images with transparent backgrounds. If I defeat an enemy, I want it to scatter like glas. Is there a way to do so? If so, how?