Java program – Image scaling

by Nideesh C on April 29, 2011 · 0 comments

in Java Programming




import java.awt.Color;

public class Scale {
    public static void main(String[] args) {
        String filename = args[0];
        int w = Integer.parseInt(args[1]);
        int h = Integer.parseInt(args[2]);
        Picture source = new Picture(filename);
        Picture target = new Picture(w, h);

        for (int tx = 0; tx < w; tx++) {
            for (int ty = 0; ty < h; ty++) {
                int sx = tx * source.width()  / w;
                int sy = ty * source.height() / h;
                Color color = source.get(sx, sy);
                target.set(tx, ty, color);
            }
        }

        source.show();
        target.show();
    }
}

 

/*************************************************************************
 *  Execution:    java Scale filename w h
 *
 *  Scales an image to w-by-h and displays both the original
 *  and the scaled version to the screen.
 *
 *  % java Scale example.jpg 200 300
 *
 *
 *************************************************************************/



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Java program – Converting color to grayscale
  2. Java program – Albers squares
  3. Java program – Luminance library
  4. Java program – Visualization client
  5. Java program – Percolation probability estimate

Leave a Comment

Previous post:

Next post: