FileDocCategorySizeDatePackage
MakeFades.javaAPI DocExample3858Sat Jan 24 10:44:36 GMT 2004je3.graphics

MakeFades

public class MakeFades extends Object

Fields Summary
public static final String[]
sizeNames
public static final int[]
sizes
public static final String[]
directionNames
public static float[]
directions
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)



        
	  
    
	// Parse the command-line arguments
	String colorname = args[0];
	float red = Float.parseFloat(args[1]);
	float green = Float.parseFloat(args[2]);
	float blue = Float.parseFloat(args[3]);

	// Create from and to colors based on those arguments
	Color from = new Color(red, green, blue, 0.0f);  // transparent 
	Color to = new Color(red, green, blue, 1.0f);    // opaque

	// Loop through the sizes and directions, and create an image for each
	for(int s = 0; s < sizes.length; s++) { 
	    for(int d = 0; d < directions.length; d++) {
		// This is the size of the image
		int size = sizes[s];

		// Create a GradientPaint for this direction and size
		Paint paint = new GradientPaint(directions[d][0]*size,
						directions[d][1]*size,
						from,
						directions[d][2]*size,
						directions[d][3]*size,
						to);

		// Start with a blank image that supports transparency
		BufferedImage image =
		    new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);

		// Now use fill the image with our color gradient
		Graphics2D g = image.createGraphics();
		g.setPaint(paint);
		g.fillRect(0, 0, size, size);

		// This is the name of the file we'll write the image to
		File file = new File("fade-to-" + 
				     colorname + "-" +
				     sizeNames[s] + "-" +
				     directionNames[d] + ".png");

		// Save the image in PNG format using the javax.imageio API
		javax.imageio.ImageIO.write(image, "png", file);

		// Show the user our progress by printing the filename
		System.out.println(file);
	    }
	}