On Apr 12, 12:49 am, "John B. Matthews" <nos...@nospam.invalid> wrote:
In article
<d44e84ed-f362-42b1-b743-bf9af2103...@i37g2000yqn.googlegroups.com>,
bH <bherbs...@hotmail.com> wrote:
Correcting error of write Image to file
Hi All,
I want to correct an error of ImageIO.write(...
1 error found:
File: C:\Documents and
Settings\bH\Desktop\OpaqueToTransparent.java [line: 39]
Error: C:\Documents and Settings\bH\Desktop\OpaqueToTransparent.
java:39: cannot find symbol
symbol : method write(java.awt.Image,java.lang.String,java.
io.File)
location: class javax.imageio.ImageIO
//fromhttp://www.rgagnon.com/javadetails/java-0265.html
//fromhttp://www.exampledepot.com/egs/javax.imageio/
[...]
public class OpaqueToTransparent extends JFrame {
...
// Use a label to display the image
JFrame frame = new JFrame();
If you extend JFrame, you don't need to create another one.
try {
File file = new File("images/cosmobX.gif");
//error on the next line
ImageIO.write(GifModifWithTransparentBackgrnd,
"gif", file);
}
You can render your transformed image in order to write it:
private void saveImage(Image image, String name) throws IOException {
BufferedImage bi = new BufferedImage(
image.getWidth(null), image.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(image, 0, 0, null);
ImageIO.write(bi, "gif", new File(name));
g2d.dispose();
}
I don't know enough about GIF format to say if that produces the result
you want. See this thread "Regarding transparent gif creation":
http://forums.sun.com/thread.jspa?threadID=5337139
catch (IOException e) {}
Don't swallow exceptions; at least write
ex.printStackTrace();
[...]
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>- Hide quoted text -
- Show quoted text -
Thanks so much for your "saveImage" help.
I have also corrected the "catch" errors you mentioned.
correct. However, the gif images do not display
with the correct oolors when saved.
The items listed in your link were observed.
a downloaded gif.
Thanks again.