ImageIO.write to save as GIF file

I have been use ImageIO.write and BufferedImage to save current Panel's paint(). with transparency.
BufferedImage image = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
components[0].paint(g2);
g2.dispose();
final File file = new File(save_File, "tt.png");
ImageIO.write(image, "png", file);success at PNG with transparency.
but now I want to save as GIF file,not png.
but I change png -> gif
final File file = new File(save_File, "tt.gif");
ImageIO.write(image, "gif", file);it will be all black color picture.
Why?
And how can I success to do this.

GIF doen't do well for transparent images. For transparent images, you can find total solutions from this theread, including the reasons why gif doen't work;
http://forum.java.sun.com/thread.jspa?threadID=5227456

Similar Messages

  • ImageIO.write not working for GIF files

    Hi, I downloaded the JAI Image IO tools which contains a class called
    com/sun/media/imageioimpl/plugins/gif/GIFImageWriter
    I am able to save png files using just the ImageIO apis and without the JAI.
    But for GIF images, I read in the forum that the JAI has a writer. Though
    the JAI documentation doesn't explicitly mention support for GIF writing,
    seeing this class in jai_imageio.jar, I thought I could write the GIF files.

    I had to create a BufferedImage with IndexColorModel
    to be able to save it as a GIF file.
    Then it worked. However, I still seem to have a
    problem with the saved image. I opened
    a GIF file and saved it back and I see that the color
    pallette has completely changed.As you know GIF format supports only up to 256 colors. That's why any good GIF encoder should contain a Java Color Quantizer to reduce the number on unique colors. The best solution I've found is the Gif4J PRO (http://www.gif4j.com/java-gif-imaging-gif4j-pro-library.htm). This library very fast and powerful and contains the fastest, most intelligent and qualitative Java color quantizer (http://www.gif4j.com/java-color-quantizer.htm).
    Regards

  • Problems with Adobe Flash Professional CC (CS6 too) to save animated .gif file or perfect .swf file

    Hello,
    I have a problem with Adobe Flash Professional CC and CS6 to save animated .gif file. Here is very simple work with logo. But I can't save a perfect file swf or gif and it's so bad news for me. Logo .swf file save with bugs. Bugs just see then file insert in freeshop page. Here is just example test page, it let you see logo bugs - http://tagraseshop.graphicsrim.eu . Here is real page, but it's not my, it's freeshop with old logo and I have corect it - http://www.tagras.lt
    Animated .gif file absoluted not saved in Flash CC. Just gif picture. And why? My os Windows 8.1 .  Indeed I try to save on Adobe Flash Professional CS6. It's not save too...
    Gif "animated" - https://mega.co.nz/#!D8pEVaRR!Gjg-nI4T-0vROV9xCa1XfXz4br1X9lpQfUR0nQNT LK4
    Swf with bugs - https://mega.co.nz/#!jo5lSRyS!1x6GjWqYsf7n4KknUs6eF8EqZXEv9e8RsSpGd8h5 jGQ
    Fla - flash document - https://mega.co.nz/#!C94nCDSS!7yKF9FIBvYtVC9r8kYiJ0l0xzUm_R2HwgoXks6iM zUA
    Perfect animation speed is here - http://e-shoptagras.graphicsrim.eu
    Who can help to me?
    Any ideas?
    Thanks for your help in advance!

    Thanks, but I use publish/export settings with GPU hardware acceleration and flash version 11.2 (and 11.8) but nothing happening.
    And why gif file is not all transparenty then I insert on lightblue background? It can't export good quality? Also I use Photoshop, After Effects, Adobe Edge Animate. And nothing happening. Egde animate file .oam is not good for old website navigation. It can't be inserted in freeshop site from navigation... I use logo file .oam just for example here - http://e-shoptagras.graphicsrim.eu
    In reality I want swf file, but we don't find why logo flickering? here http://tagraseshop.graphicsrim.eu
    All file's are transparenty - https://mega.co.nz/#!f8B2CD5R!J8uCJt9Sdq4Suz4HLhTHz8bzJcSWXMBIKcKZgkD3z8c
    I need help! Please!

  • Save as gif file

    Hi all,
    I wanted to capture the mouse movements,and diplay it and save to gif file...
    what i did is ,i captured the X and Y co-ordinates...drawn it in a panel....now ..how can i save it to GIF file...
    please help me...
    thanks in advance...

    the only way i know is jai (java advanced imaging).
    link: http://java.sun.com/products/java-media/jai/index.html
    are there any people who know how to implement saving to gif in jai ?
    tobias

  • Open write and save a txt file

    i'm trying make a vi to open and write in a txt file
    my level of LabView is very basic and, i'm looking for help for open (or create) a txt file in a specfication folder, write a value and save this file in a another folder

    you are not closing the the file in use, that is why you get the messege and your string format....
    Spoiler (Highlight to read)
    Spoiler (Highlight to read)
    Attachments:
    vti[1].vi ‏11 KB

  • Does ImageIO.write of GIF support transparent?

    I have been use ImageIO.write and BufferedImage to save current Panel's paint(). with transparency.
    BufferedImage image = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    components[0].paint(g2);
    g2.dispose();
    final File file = new File(save_File, "tt.png");
    ImageIO.write(image, "png", file);success at PNG with transparency.
    but now I want to save as GIF file,not png.
    but I change png -> gif
    final File file = new File(save_File, "tt.gif");
    ImageIO.write(image, "gif", file);it will be all black color picture.
    Why?
    And how can I success to do this.
    Does ImageIO.write of GIF support transparent?
    Or it should be some other setting ?

    Lots of questions above -- I'll answer one:
    There is a handwriting app for the iPad.  See http://www.geewhizstuff.com

  • IMAGEIO.write,  create an empty file on my filesystem

    hi,
    I'm trying to write an image to my filesystem using this method, but it just create an empty BMP file.
    I can't understand why.. I'm sure that I getAsBufferedImage returns a BufferedImage (I checked the raster in debug mode)
    ImageIO.write(planarImage.getAsBufferedImage(), "BMP", new File(pathname));thank you
    bye

    Thank you. I'm in 8i.
    SQL> SET head off
    SQL> SET pagesize 0
    SQL> SET verify off
    SQL> SET feedback off
    SQL> SET serverout on
    SQL> SPOOL empty_file.txt
    SQL> BEGIN
    2 DBMS_OUTPUT.put_line (RPAD (' ', 2000, ' '));
    3 END;
    4 /
    BEGIN
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "SYS.DBMS_OUTPUT", line 57
    ORA-06512: at line 2
    Any solution ?

  • How can one edit a .gif file graphics background and change the fonts in Photoshop Elements 13?

    I am trying to change the color and fonts of some of my web sites .gif files. Can I change the color to another hexadecimal color and change the fonts of the letters in Photoshop 13? I am using Windows 7 and heard that you could save the .gif file to another format, edit it, then change the file back to a .gif file. Is this true? If so, how do you do it? The file just has a solid color with the letters "Firm " on it. No animation.

    You can edit a gif without changing the format, but once you save the file as a gif the text becomes part of the image, not text anymore, so you would need to clone or heal away the existing text and then create a new text layer and use save for web to create a new gif.
    For access to the most editing tools, while the file is open in the editor go to image>mode and change it from index color to RGB. Saving as a gif will change it back to index mode.

  • Problems with ImageIO.write()

    Well I am finding it very strange with ImageIO.write();
    Consider the following code snippet:
    BufferedImage img=ImageIO.read(new File("fw2.jpg"));
    BufferedImage img1=new BufferedImage(img.getWidth(),img.getHeight(),img.TYPE_INT_ARGB);
    for(int i=0;i<img.getHeight();i++)
    for(int j=0;j<img.getWidth();j++)
    img1.setRGB(j,i,img.getRGB(j,i));
    ImageIO.write(img1,"jpg",new File("fwinv.jpg"));
    So simply I am copying fw2.jpg to fwinv.jpg. fw2.jpg was also created
    using ImageIO.write().
    But the two files are having different pixel values.
    i.e If I read fwinv.jpg again I will get different pixel value that it was written.
    Why is this...Can any one please help me..

    Reading the written images back and displaying them in java works okay. The third image looks okay in RGB but wrong in ARGB when displayed by a native app. For more about this see reply 1 in Color problems and the linked bug report: Some Images written using JPEG Image Writer are not recognized by native applns.
    import java.awt.GridLayout;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class WriteTest {
        private JPanel getContent(BufferedImage src) throws IOException {
            File fileOne = new File("fileOne.jpg");
            ImageIO.write(src, "jpg", fileOne);
            BufferedImage image1 = ImageIO.read(fileOne);
            BufferedImage image2 = copy(image1);
            JPanel panel = new JPanel(new GridLayout(1,0));
            panel.add(new JLabel(new ImageIcon(src)));
            panel.add(new JLabel(new ImageIcon(image1)));
            panel.add(new JLabel(new ImageIcon(image2)));
            return panel;
        private BufferedImage copy(BufferedImage in) throws IOException {
            int w = in.getWidth();
            int h = in.getHeight();
            int type = BufferedImage.TYPE_INT_ARGB;   // problem in native apps
                       //BufferedImage.TYPE_INT_RGB;  // this one works okay
            BufferedImage out = new BufferedImage(w, h, type);
            for(int y = 0; y < h; y++) {
                for(int x = 0; x < w; x++) {
                    out.setRGB(x, y, in.getRGB(x, y));
            File fileTwo = new File("fileTwo.jpg");
            ImageIO.write(out, "jpg", fileTwo);
            return ImageIO.read(fileTwo);
        public static void main(String[] args) throws IOException {
            BufferedImage image = ImageIO.read(new File("images/cougar.jpg"));
            WriteTest test = new WriteTest();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test.getContent(image));
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Saving large PNG files with ImageIO.write

    I have a program that draws onto a DrawPanel (extends JPanel) which is inside of a JInternalFrame. I have used ImageIO.write to successfully save the drawing as a PNG file, but a most unexpected thing happens if the image to be saved is larger than my desktop resolution. For instance, if the DrawPanel/output image is 1200*1200 pixels in size and my desktop resolution is 1024*768, I end up with a PNG file of 1200*1200 pixels that is a tiled image of the first 1024*768 from the upper left corner of the desired image.
    Here is the portion of code responsible for exporting the image:
    JInternalFrame jif = desktop.getSelectedFrame(); //desktop is a JDesktopPane
    DrawPanel dp = jif.getDrawPanel();
    BufferedImage image = new BufferedImage(dp.getWidth(), dp.getHeight(),
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    dp.paint(g2d);
    g2d.dispose();
    ImageIO.write(image, "png", targetFile);
    I could very easily prevent the user from saving an image if it is bigger than the desktop resolution, but it is a necessity that large images can be saved.
    Any help would be appreciated.

    I've taken a look at that, on your recommendation, but I get the impression that this will filter the image and throw away information. Is this the case? The image will contain narrow lines and small text, so that woudn't be really be an option. I still want the image to be the full size it should be.
    I had a go at incorporating it into my code, anyway, but I'm not really sure how to. Would I need to capture the image in some way other than with a BufferedImage?

  • How to to read/write GIf files (not animated)

    Hi,
         Is there a labview vi(s) that will read a gif file and display it and also that will wirte it? I am interested in non animated gifs.
         Louis

    Ben wrote:
    Well before Mike got carried away in this thread the answer to those questions was "NO".
    But if you check that thread you will see that Mike has already done half of the work (reading a gif).
    There is limited functionality for writing a GIFin LabVIEW, look in vi.lib\picture\gif.llb\Write GIF File.vi
    Message Edited by Phillip Brooks on 10-09-2008 04:24 PM
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • How to capture a .gif file from a spectrum analyzer and save the file in PC

    I want to capture a .gif file from a spectrum analyzer and save the file in PC, but I've got a problem when read data from the instrument. I'm not sure how to format the string got from the instrument , When I use "%s" or "%t" as the read string format the data got from the instrument is truncated.
    my code are as follows, could anyone tell me where i am wrong?
    char resultsArray[5000];
    viPrintf(hSpectrumInstr, ":MMEMTORCR 'CICTURE.GIF'\n");
     viQueryf(hSpectrumInstr, ":MMEMATA? 'CICTURE.GIF'\n", "%t", resultsArray);
     printf("%s", resultsArray);
     getchar();       
    Solved!
    Go to Solution.
    Attachments:
    readResult.docx ‏50 KB

    char resultsArray[5000];
    viPrintf(hSpectrumInstr, ":MMEMTORCR 'CICTURE.GIF'\n");
    viQueryf(hSpectrumInstr, ":MMEMATA? 'CICTURE.GIF'\n", "%b", resultsArray);

  • How can I save a Image to a GIF file??

    Class Image ---------> GIF file
    How can I do it??

    Who can help me??
    Image my_image=Tookit.getDefaultToolkit.getImage("cc.gif");
    Now,I want to save my_image to a .GIF or .JPG file.
    Who can tell me what I am able to do next or what class I need.

  • How do I write JPG or GIF files

    Hi,
    Is there anyway I can write the Image object into GIF or JPG file appropriately?
    Thanks!
    Regards,
    Thomas.

    I replied to a similar question in the Java programming forum. Here is the URL:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=174657
    Here are steps to convert Image to BufferedImage,
    1. Construct a BufferedImage object
    2. Get the graphics context
    3. Draw the Image object over this graphics context.
       public static BufferedImage convertToBufferedImage(Image img,
                                         int wid, int ht, int type){
           BufferedImage bi = new BufferedImage(wid, ht, type);
           Graphics2D g2d = bi.createGraphics();
           g2d.drawImage(img, 0,0,wid, ht, null);
           return bi;
       }The type parameter represents the type of the BufferedImage (such as TYPE_INT_RGB). See the Javadocs for the BufferedImage class.
    To write to a GIF file, you may have to use a commercial package.

  • How do you you create, write, and save files?

    I created a VI to read 8 channels and display the waveform, which it does. But whenever I try to set up a way to save the data it never works. I want it to give me the option to create a new file, then write the data to there, and save it, and then close the file. How should I go about this?

    I have not opened your attachment, yet.
    Before doing so, you will need to decide if you want to write to:
    a) a measurement file
    b) a regular text file, or
    c) MS Excel Spreadsheet
    The method to write to the above are quite different.  Please decide and let us know..
    R

Maybe you are looking for

  • Not able to clear GR/IR accont

    Hi, We are executing transaction code F.13 to clear GR/IR account. However, still there are some documents appearing in the account as uncleared. For all the documents unclaered, two accounts are involved: one for GR and other one for IR. We tried tr

  • How can I sync my new Mac to my iphone?

    I knew my old computer was giving up on me so I was trying to back up my iTunes on my old HP computer on an external drive...but I was too late! It crashed before I could back it up somewhere else.  The good thing is that I was able to sync my phone

  • I have downloaded an app called My Data Manager but i can no longer find it in App Store to share with friends

    My Data Manager by Mobidia appeared in the App Store and I downloaded it for testing. I updated to IOS 7.1.2 I was impressed with the app so I sent the link to other iPhone users for them to try whilst we tried out our iPhone Pilot. When they searche

  • Installing Flash Player with IE 11

    When I open a PDF, I'm prompted to download the latest Flash Player. After downloading,I get the following error message: Your Microsoft Internet Explorer browser includes the latest version of the Adobe Flash Player built-in. Windows Update will inf

  • How to find all oaf pages that are using a table in their VOs

    Hello everyone, I need to findout all the View Objects and Entity Objects that are using a table lets say A. Is there a smart way to find out all the VOs and EO's that are using my table? Thanks Sunny