Creating a Brushed Metal Texture
This article explains how to create a brushed metal texture using Java, and provides source code for a filter which produces such a texture. You can use the filter freely in your own code and modify it in any way you like.
An Example: Metal Text
A brushed metal effect is quite easy to produce. We start with a plain image filled with the color of our metal, and then add some random noise to it:
A Noisy Image
Next we need to blur the image. I'm only going to worry about blurring horizontally because that can be done very fast. You can always rotate the image afterwards if you want the brush marks to go in a different direction, or you can use a slower blur algorithm. The blur I'm using is a simple box blur along the horizontal axis which wraps round at the edges so that the resulting image doesn't have any edge effects and will also be tilable if you want to use it as a repeating texture.
Blurring the Image
Finally, for that extra pizazz, we'll add a little shine to the image. We can do this by adding an image which looks like this to our image:
Put it all together, and this is what we get:
I've packaged this up into a BufferedImageOp which you can use like this:
BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB ); image = new BrushedMetalFilter( ... ).filter( image, image );
The filter has five parameters:
- Color - the color of the metal.
- Radius - the "radius" of the blur.
- Amount - the amount of noise to add (range 0-1).
- Monochrome - true if the noise should be monochrome.
- Shine - the amount of shine to add (range 0-1).
You can play with the filter using this applet here:
That's it! feel free to email me with any questions.