Draw On Panel/Save as GIF problem

Hi everyone,
I am designing an application where the user should be able to free draw on a JPanel(that resides on a JFrame) by licking/dragging/releasing the mouse.
Then, this drawing needs to be saved as a GIF image.
OK. I have managed to implement a free-draw algorithm but now I am having problems saving the GIF. I think I kinda know where the the problem is, but I can't find any ways around it.
I am using a Graphics2D class to draw the lines, and I am using the .setClip method to assossiate my graphics object to the JPanel,i.e.
g.setClip(jPanel1.getX(), jPanel1.getY(), jPanel1.getWidth(), jPanel1.getHeight());
I think that this is where the problem is. I believe that eventhough I can actually see the line drawn by the user @ runtime, the line itself is not "added" onto the JPanel, it just draws itself onto the area that the JPanel occupies.
Hence, when I attempt to save the JPanel as a GIF(using an Acme.JPM.Encoder), the saved image appears monochrome, without any lines on it at all.
The free-draw algorithm that i am using involes saving all the coordinates of the area where the mouse is being dragged into a Vector of Points which I have to repaint() whenever a new drag is listened.
Any help would be greatly appreciated,
thanks
Yiannis

Hi Ashwin,
I have created a class that can take a JPanel and save it into GIF.
the code is:
import javax.swing.*;
import java.io.*;
import java.awt.image.*;
import java.awt.Graphics;
import Acme.JPM.Encoders.*;
public class saveToGIF {
private JPanel panel;
/** Creates a new instance of saveToGIF */
public saveToGIF(JPanel panel, String file) throws IOException{
this.panel=panel;
BufferedImage image = new BufferedImage(this.panel.getWidth(), this.panel.getHeight, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
panel.paint(g);
FileOutputStream fos = new FileOutputStream(file);
GifEncoder encoder = new GifEncoder(image, fos);
encoder.encode();
fos.close();
OK, this works fine. However, I cannot add my drawings onto the JPanel.
Sth with overwritting the paintComponent() method is what i do no fully nderstand.
Thanks,
Yiannis

Similar Messages

  • 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!

  • Animated Gif Problem

    Greetings
    I would appreciate some help.
    I am new at creating animated gif's, and am experiencing a
    problem with them when I try to view them in a browser.
    I am working in Fireworks 2004, the following is what I do.
    Create first frame.
    Insert simple arrow.
    Create second frame
    Insert simple arrow with diffrent color
    Third frame same but diffrent image.
    Set the Optimize Panel to Animated Gif, transparency set to
    No tranparency.
    Click on File, Export.
    Type the name of the file in File Name box.
    Select "Frames to Files" option for Save as type option.
    In my folder where I saved the files there are now three gif
    files.
    When I open the file into the following browsers IE 7, 6.0 or
    Firefox it remains as a static image in the browser with no
    animation, the same is for viewing it in Window Explorer Preview
    Pane.
    In Fireworks however the animation plays perfectly.
    I would really appreciate it if someone could tell me what I
    am doing wrong or why they created animated gifs are not playing in
    the browser.
    Regards
    Dave

    Instead of Frames to files on export, select Images only.
    that should do it -
    alex
    revbear wrote:
    > Greetings
    >
    > I would appreciate some help.
    >
    > I am new at creating animated gif's, and am experiencing
    a problem with them
    > when I try to view them in a browser.
    >
    > I am working in Fireworks 2004, the following is what I
    do.
    >
    > Create first frame.
    > Insert simple arrow.
    > Create second frame
    > Insert simple arrow with diffrent color
    > Third frame same but diffrent image.
    >
    > Set the Optimize Panel to Animated Gif, transparency set
    to No tranparency.
    >
    > Click on File, Export.
    > Type the name of the file in File Name box.
    > Select "Frames to Files" option for Save as type option.
    >
    > In my folder where I saved the files there are now three
    gif files.
    >
    > When I open the file into the following browsers IE 7,
    6.0 or Firefox it
    > remains as a static image in the browser with no
    animation, the same is for
    > viewing it in Window Explorer Preview Pane.
    >
    > In Fireworks however the animation plays perfectly.
    >
    > I would really appreciate it if someone could tell me
    what I am doing wrong or
    > why they created animated gifs are not playing in the
    browser.
    >
    > Regards
    > Dave
    >
    >

  • How to save transperant gif

    I am building a generic graph package and I wanted to capture the graph (image) and save it into a GIF file with a transperent background.
    I have been struggling with the transperant part for a whole day, but now I finally found how to do it and I just wanted to share this knowledge with the rest of you.
    <b>1.) Generate the Graph</b>
    I created two new methods BufferedImage getImage() and void drawImage( Graphics2D )
    <pre>
    public BufferedImage getImage( int width, int height ) {
    BufferedImage bufImage = new BufferedImage( width, height, BufferedImage.TYPE_4BYTE_ABGR ); //Create a new BufferedImage
    Graphics2D graphics2D = bufImage.createGraphics(); //Creates a Graphics2D, which can be used to draw into this BufferedImage
    graphics2D.setColor( new Color( 255, 255, 255, 0 ) ); // The last int is the alpha value and 0 will make the Color transperent
    graphics2D.fillRect( 0, 0, width, height ); // Fill a Rectangle with the same size as the image with the transparent color
    drawImage( graphics2D ); //Draw the actual graph on the transparent Rectangle
    return bufImage; //Return the BufferedImage
    </pre>
    <pre>
    public void drawImage( Graphics2D g ) {
    drawGraph( g ); //Draws the axis
    putValues( g ); //Draws the actual values/graph
    </pre>
    <b>2.) Paint the Graph in you Component (Panel/JPanel, Frame/JFrame, etc)</b>
    <pre>
    public void paint( Graphics g ) {
    Dimension bounds = this.getSize(); //Get the Dimension/Size of the Component
    g.drawImage( getBufImage( bounds.width, bounds.height ), 0, 0, this ); //Get the BufferedImage and draw it on the Components Graphics Object
    </pre>
    <b>3.) Save the Graph into a GIF file</b>
    <b>3.1. Download the Acme package to be able to save to GIF</b> (You will only need the GifEncoder, ImageEncoder and IntHashtable).
    <b>3.2. Save to GIF</b>
    <pre>
    import Acme.*;
    import Acme.JPM.Encoders.*;
    public void saveGIF( String filename, int width, int height ) {
    BufferedImage bufImage = getBufImage(); //Get the BufferedImage with the Graph drawn on a transparent Rectangle
    Graphics2D graphics2D = bufImage.createGraphics();Creates a Graphics2D, which can be used to draw into this BufferedImage
    graphics2D.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR ); //Sets the value of a single preference for the rendering algorithms
    try {
    GifEncoder gifcoder = new GifEncoder(bufImage, new BufferedOutputStream( new FileOutputStream( fileName + ".gif" ) ) ); //Create a new GIFEncoder for the BufferedImage and a OutputStream
    gifcoder.encode(); //Write the image into GIF
    catch( FileNotFoundException fnfe ) {
    System.err.println( "error: MGraph.saveImage( String ): " + fnfe );
    catch( IOException ioe ) {
    System.err.println( "error: MGraph.saveImage( String ): " + ioe );
    </pre>
    That's it! I hope this will be helpful and save you some time.
    /Max

    I am also going to start to build some form of graphic plot toolkit for a project in my university. I would be great to know how you have defined your API and how the output of the graphs look like. If you are willing to share that?
    Regards,
    Peter.

  • PSE 9 does not save transparant GIF's

    The background eraser in PSE 9 does not work correctly, in that it erases very small areas instead of size of the setting.  Then when I save a GIF transparant background the background is white.  I've just upgraded from PSE8 to 9, and did not have this problem with version 8 & I'm using the same settings. The attached photo was saved with the top part transparant around 'OFFICE HELP'  ditto the lower part around the 'NAMES'  Does nyone know have a Fix?

    If you want a better way to remove white around text (or anything on white), you could
    use this plugin called Kill White. The 32 bit filter is the one and after you unzip, the
    filter goes in the pse 9 plugins folder.
    http://yaelmaritz.com/extras_killWhite.html
    Make sure your layer is a regular layer and not a locked background layer.
    Then make a selection around the text and run the filter.
    Before filter
    After filter
    No white left around the text
    Of course you have the option of making new text unless preserving the original
    text is crucial.
    MTSTUNER
    Message was edited by: MTSTUNER

  • 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

  • When trying to save a GIF in Photoshop CS6 it turns my pure white background blue, why would this be happening?

    When trying to save a GIF in Photoshop CS6 it turns my pure white background blue, why would this be happening?

    What exact palette and other settings do you use?
    Could you please post screenshots (with the Layers Panel visible) of the original file and the resulting gif?

  • 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

  • Save as list problem

    I have a save as/export problem. Im using cs6 for windows and it shows me 6 options for saving as psd, psb, exr, raw, bitmap, radiance and tiff but there is no jpeg or pdf or any other options listed. How can I bring these options to this list? is it a problem like fixing acrobat X with a patch?

    Hi,
    Check under Image>Mode as it sounds like maybe your image is 32 bits/channel.
    If you switch to 16 or 8 bits/channel then jpeg should become available.

  • How to solve illustrator cs6 save as cs5 problem about the stroke(when the stroke with clipping mask and color is gradient, save as cs5 will change to embed ).

    how to solve illustrator cs6 save as cs5 problem about the stroke(when the stroke with clipping mask and color is gradient, save as cs5 will change to embed ).

    Because it was not possible to apply a gradient to a stroke in CS5. When you open the file in CS5, it is reduced to something that can be rendered in CS5.

  • Photoshop Save as GIF with flatten

    I have a script which is supposed:
    1) Save a Photoshop file as GIF
    2) Change the color of some text in a text layer
    3) Save another copy as GIF
    Here's what I have so far:
    save current document in filelocation & BaseName & "_ov" as CompuServe GIF appending lowercase extension with copying
    set stroke color of text object of artLayerRef to {class:RGB color, red:0, green:0, blue:204}
    save current document in filelocation & BaseName as CompuServe GIF appending lowercase extension with copying
    It's fine except the save as GIF parts make a dialog box pop up asking if I want to flatten the image. Is there a command I can put in the save code that will save the file flattened? Or, is there a way to undo flattening (using the history or undo command), so that I can flatten the file, save as GIF, undo flatten, change the text layer, flatten, save as GIF?

    Hello,
    Often when working with Photoshop users recommend creating a Photoshop action that will do what you want and then calling the action from Applescript.
    tell application "Adobe Photoshop CS2"
    do action the name of the action from name of the action set the action is in
    end tell
    I hope this helps. It should run quicker than using System Event.
    - Zoar
    Mac Dual G5   Mac OS X (10.4.3)  

  • JIMI - Save as GIF, impossible?

    I wish to write an application that, eventually, needs to save a series of images as an animated GIF. I read that JIMI can do such a thing, but have found that there is no encoder for GIF, only a decoder.
    Is it impossible to save as GIF with JIMI? If so, is there anything that comes close to the simplicity of JIMI that can save as GIF?

    From the top hits on Google:
    {color:0000ff}http://download.eclipse.org/eclipse/downloads/documentation/2.0/html/plugins/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/ImageLoader.html
    http://rsbweb.nih.gov/ij/developer/api/ij/plugin/GifWriter.html{color}
    Plenty more if you care to search.
    db

  • Draw a Panel based on pixel?

    hi all....does anyone know how to draw on panel based on the given pixels?
    The normal panel is in plain white background. I'm developing a canvas that will draw what other has drawn based on the pixel, thus i need to redraw the pixels into the canvas (panel).

    There are a bunch of ways.
    1) Build each table, put it in the scrollpane, add it to a panel. Add all panels to another one with a Card Layout. Place that panel in your main GUI. Use the ComboBox to switch between cards.
    2) Build all tables, add them to panels, add a blank panel to a scrollpane, add the scroll pane to your GUI. Use the Combobox to select the table, remove whatever is in the scrollpane, then add the panel containing the table you want (this is done a lot easier if the panels holding the tables are in an array or collection). Finally, validate the scrollpane.
    3) Use the combobox to select the table. Build it on the fly, add it to a scrollpane then add the scrollpane to the GUI and validate the GUI.
    APIs to look at:
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/CardLayout.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html
    or anything that implemens: http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html
    Swing:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JScrollPane.html
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JPanel.html
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComboBox.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/ActionListener.html
    AWT:
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/ScrollPane.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Panel.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Choice.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/ItemListener.html

  • Save as GIF

    Im trying to run a very simpke process where I take multiple images, resize them to 40 x 40 and save them as .GIF but under the "convert image" process the pop up menu does not have this option, only jpef, tiff and a few others but no .gif!
    Anyone know away to do this please?
    Regards

    The freeware ImageTricks @ http://www.macupdate.com/info.php/id/19033 will save in gif format.
     Cheers, Tom

  • Illustrator Save to PDF problems

    I have Illustrator CS 14.0.0 and Acrobat Pro 9 (9.1.1 to be specific) extended and I cannot save the pdf format from Illustrator. I try over and over and it just does not work... it just locks up Illustrator forcing me to use the Windows XP task manager to kill Illustrator becuase it is simply frozen and I have no other options. The failure is happening with large and small files of any complexity. I would like to make use of the streamlined workflows in CS4... but his problem is big headache - especially if I would like to include special aspects of Illustrator features in the PDF file. The failure happen with save-as and with the basic save PDF. I was able to open (more or less like an import) the .ai file after saving from within Acrobat and that seems to be a work around for now. Is ther any updates for Acrobat or Illustrator to fix this save as PDF problem inside Illustrator CS4??

    I am experiencing exactly the same problem as reported in this thread.  I am using AI CS4.  When I try to save to PDF the programme freezes making it necessary to use the task manager to kill it.  I have been trying to identify the folders where the preferences are held but on this computer running windows xp the folder names do not match those in the thread.  Is there a specific file name that I can search for?

Maybe you are looking for

  • I can't playback a video I purchased on itunes

    I purchased Fleetwood Mac The Dance on Itunes.  I was able to play it back once on my Ipod Touch but now I am unable to do so.  It is clearly marked as an item for synching on Itunes and when I search for it on my Ipod Touch and play the screen just

  • Hai everybody - i got a problem plese resolve it.

    I have a complied a bean that is located in the webapps/project/WEB-INF/classes directory. When I execute my jsp page, I get the error: type Exception report message description The server encountered an internal error () that prevented it from fulfi

  • Compressor 3 won't recognise aspect ratio

    I have an FCP6 Project with many sequences all of which were edited in 16x9.  The source footage is DVCPRO 720 and I have been editing in standard DV widscreen I have tried exporting the time line through Compressor but it outputs it as 4x3.  I have

  • Blackberry Sync

    Hi, I wish to sync my Blackberry to my Mac Book Pro, but I need a one way sync only from Blackberry to Mac. The Blackberry Desktop Software for Mac does not show any option for a one way sync (like the Blackberry Desktop for Windows, which has three

  • How to maitain user creation and authorization in Portal from CUA

    Hi , I want to create portal users in CUA i.e. instead of creating users in portal I want to maintain user administration from CUA and also want to assign the required portal roles from CUA what configuration I need to perform. Please help. Sandip