2
import java.awt.image.*;
4
import java.util.regex.*;
5
import javax.imageio.*;
7
public class MenuIcons {
8
public static void main ( String ... args ) throws Exception {
9
if ( args.length < 4 ) {
10
System.out.println ( "USAGE: java MenuIcons DIRECTORY ANIMATION_NAME ANIMATION_FRAME ICON_SIZE" );
13
File path = new File ( args [0] );
14
String anim = args [1];
15
int id = Integer.valueOf ( args [2] );
16
int size = Integer.valueOf ( args [3] );
18
Pattern pattern = Pattern.compile ( anim + "_0*" + id + ".png" );
19
for ( File f : path.listFiles ())
20
if ( pattern.matcher ( f.getName ()).matches ()) {
21
System.out.println ( "[" + path.getName () + "] Using image " + f.getName ());
22
BufferedImage img = ImageIO.read ( f );
23
int w = img.getWidth ();
24
int h = img.getHeight ();
25
double scale = Math.min ((double)size / w, (double)size / h );
26
int nw = (int)( scale * w );
27
int nh = (int)( scale * h );
29
BufferedImage write = new BufferedImage ( size, size, BufferedImage.TYPE_INT_ARGB );
30
Graphics2D g = write.createGraphics ();
31
g.drawImage ( img.getScaledInstance ( nw, nh, BufferedImage.SCALE_SMOOTH ),
32
size / 2 - nw / 2, size / 2 - nh / 2, nw, nh, null );
34
ImageIO.write ( write, "png", new File ( path, "menu.png" ));
37
System.out.println ( "[" + path.getName () + "] Frame " + id + " of animation " + anim + " not found at " + path );