Thank you for replying
after acquiring the image I simply display it this way.
public void paint(Graphics g)
{ if (null!=image)
g.drawImage(image, 20, 40, this);
}
}
I found out some code that saves my image as "SaveTest.jpg". but I want to save many images using counter.
public void save()
{ try
{ File f=new File("SaveTest.jpg");
BufferedImage bimg=new BufferedImage(image.getWidth(null),
image.getHeight(null), BufferedImage.TYPE_INT_RGB);
bimg.createGraphics().drawImage(image, 0, 0, null);
FileOutputStream out=new FileOutputStream(f);
JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param=encoder.getDefaultJPEGEncodeParam(bimg);
param.setQuality(1.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(bimg);
out.close();
}
catch (IOException e)
{ e.printStackTrace();
}
}
by the way, isn't there any dialog boxes allowing me to save my image when the user request?
You can use the saveFileDialog here some code I have for it:
JFileChooser chooser = new JFileChooser();
int retval;
//Then you do this to display it
returnVal = chooser.showSaveDialog(this);
//after that you can use if statements on the options chosen
if (returnVal == JFileChooser.APPROVE_OPTION)
{
As for the saving problem your having, I'll have to look that up a little later..I'm getting ready for schoo right now :)
See, I just don't know how to get a reference to where your drawing it using the graphics object.
Now here's how I saved contents of a what was in my textpane into a file
textPane.write( new FileWriter(getFile));
getFile is a string holding the file chosen in the JFielChooser.
Now, if we knew how to reference the drawing area, we could probably just replace textPane with the reference
thank you james
I am not good enough in java programming. I still don't know how to hold the file Chosen in the getFile string. I wish you illustrate it in more code.
Moreover, how can I save a sequence of files using a counter.
public ImageFrame(TwainSource source)
{ super("Image: "+frameCount);
...
...
frameCount++;
save();
}
}
but the save(); will replace the old one, i.e. in every loop the new image is saved in the same file SaveTest.jpg. as illustrated in my first post.