dcsimg
Problem in Storing Images as .gif file? Please Help?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chelikani_madhukumar
Posted On:   Wednesday, July 24, 2002 05:22 PM

I have two image objects which i displayed in an applet.My intention is to provide a button on which if you click i need to save those two images as .gif file? The first image is getting saved well into the file well. But the second image is not seen in the file. I am pasting the code that I am using here.Probably somewhere i am doing mistake. I would be grateful if somebody can help me. The method which is called after click on the button is(This method is in diff class) public void saveAsGIF() { FileDialog fd = new FileDialog(Util.getFrame(this), "Save As", FileDialog.SAVE); Image selectedImage=null;    More>>


I have two image objects which i displayed in an applet.My intention is to provide a button on which if you click i need to save those two images as .gif file?


The first image is getting saved well into the file well. But the second image is not seen in the file.


I am pasting the code that I am using here.Probably somewhere i am doing mistake. I would be grateful if somebody can help me.


The method which is called after click on the button is(This method is in diff class)


public void saveAsGIF()
{


FileDialog fd = new FileDialog(Util.getFrame(this), "Save As", FileDialog.SAVE);



Image selectedImage=null;


fd.setFile("*.gif");


fd.show();


String curFile = fd.getFile();



if (curFile != null)
{


String fname = fd.getDirectory() + curFile;


System.out.println("fname "+fname);


File f = new File(fname);


try


{


Image upperGraphImage=upperGraph.getGraphImage();



Image lowerGraphImage=lowerGraph.getGraphImage();





if( upperGraphImage !=null && lowerGraphImage !=null){


GifDemo demo=new GifDemo (fname,f,upperGraphImage,lowerGraphImage);


demo.print();
}



}catch (IOException e)
{
System.out.println("IntradayPanel.saveAsGIF(): " + e);
}
}


}


The GifDemo.java

import java.applet.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;

import com.saven.util.*;


public class GifDemo
{
Image imageOff_;


Image imageOff1_;


File f;


String text;


String fname;


public GifDemo(String fname,File f,Image imageOff_, Image imageOff1_){


//System.out.println("Text in Constructor"+text);
this.f=f;


this.fname=fname;


this.imageOff_=imageOff_;


this.imageOff1_=imageOff1_;


}
public void print() throws IOException


{


try


{


FileOutputStream fos = new FileOutputStream(fname);


GifEncoder gifEncoder = new GifEncoder(imageOff_, fos);


gifEncoder.encode();


GifEncoder gifEncoder1 = new GifEncoder(imageOff1_, fos);


gifEncoder1.encode();


fos.close();


}
catch (IOException ioe)



{
System.err.println(ioe);



}
}



}

   <<Less
About | Sitemap | Contact