Solved

Find dimensions of directory/GIF/JPEG

Posted on 2011-02-11
4
625 Views
Last Modified: 2013-11-23
Dear Experts,
I would like to produce below result for my own small program
Which will find out length , size and compression of directory JPEEG and GIF images.
Any one can help me with JAVA core programming here..

C:\Java Programt>java PicInfo pic1.jpg
name: pic1.jpg, type: JPEG-image
  length:      68676
  size:        1050 x 681
  compression: 4%

Thank you in advance:-)

0
Comment
Question by:rachel88
4 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 250 total points
ID: 34871167
0
 
LVL 4

Accepted Solution

by:
aaver earned 250 total points
ID: 34936913
I think this should be helpful to start with:
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageInfo {
    public static void main( String[] args ) throws IOException {
	for (String fileName : args) {
	    File file = new File( fileName );
	    BufferedImage image = ImageIO.read( file );
	    System.out.println( "name: " + fileName );
	    System.out.println( "type: " + (fileName.toLowerCase( ).endsWith( "jpg" ) ? "JPEG-image" : "GIF-image") );
	    System.out.println( "size: " + image.getWidth( ) + " x " + image.getHeight( ) );
	    System.out.println( "length: " + file.length( ) );
	    System.out.println( "compression: " + (100 * file.length( ) / (image.getRaster( ).getNumBands( ) * image.getWidth( ) * image.getHeight( ))) + "%" );
	}
    }
}

Open in new window

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36923063
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now