Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
kalyani guntupalli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which line is the Exception thrown?
 
kalyani guntupalli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kalyani guntupalli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic