aspose file tools*
The moose likes I/O and Streams and the fly likes How can i know the data that is read from the .gif file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How can i know the data that is read from the .gif file" Watch "How can i know the data that is read from the .gif file" New topic
Author

How can i know the data that is read from the .gif file

kalyani guntupalli
Greenhorn

Joined: Aug 24, 2007
Posts: 5
HI ALL,

My project is image(.gif) file to DoC conversion
to read .gif file,imported and used Thirdparty package com.gif4j.
inorder to know the data that is read from the gif file i have used below two lines of code:
GifImage gifImage = GifDecoder.decode(file);
int j= gifImage.getNumberOfFrames();
String s=gifImage.getComment(j);
but it is throwing an exception saying that 'Exception in thread main'

what can i do now to know that data which i have read?
please suggest me!since i am a fresher,and my boss is not helping to me!

Regards,
kalyani.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41808
    
  62
In which line is the Exception thrown?


Ping & DNS - my free Android networking tools app
kalyani guntupalli
Greenhorn

Joined: Aug 24, 2007
Posts: 5
Hi Ulf,
here i am sending my code.exception is coming after printing the number of frames.
here is my code:

package gif.doc;
import com.gif4j.GifDecoder;
import com.gif4j.GifFrame;
import com.gif4j.GifImage;
import java.awt.image.IndexColorModel;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
* Load a GIF Image and Extract GIF File Format Meta Info
*/

public class GifImageLoad {

// Usage: java GifImageLoadExample [PathToGifImageToLoad] (please be sure that the gif4j jar is in your CLASSPATH)
// By default the gif4j_logotype.gif as an example gif image is used
public static void main(String[] args) {
if (args.length == 0) {
File gifImageFile = new File("D:/Myapps/read/4843a349.gif");
GifImageLoad gifImageLoadExample = new GifImageLoad();
try {

System.out.println("");
gifImageLoadExample.loadGifImageAndExtractMetaInfo(gifImageFile);
} catch (IOException e) {
e.printStackTrace();
}
} else {
GifImageLoad gifImageLoadExample = new GifImageLoad();
for (int i = 0; i < args.length; i++) {
File gifImageFile = new File(args[i]);
System.out.println("-------" + args[i] + "-------");
System.out.println("");
try {
gifImageLoadExample.loadGifImageAndExtractMetaInfo(gifImageFile);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("");
}

}

}

public GifImage loadGifImageAndExtractMetaInfo(File file) throws IOException {
// load and decode gif image from the file
GifImage gifImage = GifDecoder.decode(file);
// print general GIF image info
System.out.println("gif image format version: " + gifImage.getVersion());
System.out.println("gif image logic screen width: " + gifImage.getScreenWidth());
System.out.println("gif image logic screen height: " + gifImage.getScreenHeight());
// check if one or more comments present
if (gifImage.getNumberOfComments() > 0) {
// get iterator over gif image textual comments
Iterator commentsIterator = gifImage.comments();
while (commentsIterator.hasNext())
System.out.println(commentsIterator.next()); // print comments
}
System.out.println("number of frames: " + gifImage.getNumberOfFrames());
int j= gifImage.getNumberOfFrames();
String s=gifImage.getComment(j);

// below we iterate frames in loop
// but it can also be done using Iterator instance: gifImage.frames()
for (int i = 0; i < gifImage.getNumberOfFrames(); i++) {
System.out.println("------frame(" + (i + 1) + ")---------");
GifFrame frame = gifImage.getFrame(i);
System.out.println("width: " + frame.getWidth());
System.out.println("height: " + frame.getHeight());
System.out.println("position: " + frame.getX() + "," + frame.getY());
System.out.println("disposal method: " + frame.getDisposalMethod());
System.out.println("delay time: " + frame.getDelay());
System.out.println("is interlaced: " + frame.isInterlaced());


}
return gifImage;
}
}

Regards,
kalyani.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8900
    
    8

Originally posted by kalyani guntupalli:

My project is image(.gif) file to DoC conversion


The gif4j library does not convert GIF files to DOC files, so it will not get you any closer to your goal.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
kalyani guntupalli
Greenhorn

Joined: Aug 24, 2007
Posts: 5
but my boss asked me to show the content that is read in gif file by using that library gif4j.

He told that he could tell how to convert into doc file!
aftet showing the content of gif file...
can you please help me?

Regards,
kalyani
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8900
    
    8

can you please help me?


I already have. What part of my answer do you have a problem with?
If you want to display an image, have a look at the Swing tutorial.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i know the data that is read from the .gif file