• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

Find dimensions of directory/GIF/JPEG

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
rachel88
Asked:
rachel88
2 Solutions
 
aaverCommented:
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
 
Kevin CrossChief Technology OfficerCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now