Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Main {
    BufferedImage img;

    public static int getWidthFromImage(String filename) {
        BufferedImage image;
        try {
            image = ImageIO.read(new File(filename));
            return image.getWidth();
        } catch (IOException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
        return -1;
    }

    public static void main(String args[]) {
        System.out.print("The width of the image in pixels is: " + getWidthFromImage(args[0]));
    }
}