Drawing moving GIF images?

Is it possible to draw moving gif images on a simple Frame applet?
I made an image drawer class for my applet and i can draw simple 2d images.
Here is the basis of my GameSprite class;
    public byte[] pixels;
    public int width;
    public int height;
    public GameSprite(String imageName, int requestIndex) {
     try {
                // Removed code, it's zipInputStream, but it can be used just as ./image.jpg etc
     javax.swing.ImageIcon icon = new javax.swing.ImageIcon(fileBytes);
     width = icon.getIconWidth();
                 height = icon.getIconHeight();
                 pixels = fileBytes;
     } catch(Exception e) {
          e.printStackTrace();
    public void drawSprite(int x, int y) {
     try {
          Image image = Toolkit.getDefaultToolkit().createImage(pixels);
                                //Removed code here
          graphics.drawImage(image, x, y + 7, width, height, observer);
     } catch(Exception e) {
          e.printStackTrace();
    }If i try to draw an animated gif image it dosn't move.
Thanks for any help.

In Java you need to override the paint method in AWT and paintComponenet method in SWING to do graphics/animation. If you go to an offscreen rendering, then you can paint to the graphics context of an image you use for a drawImage in your paint/paintComponent...
If you where overriding a Panel in AWT you would override paint:
public void paint(Graphics g){
  g.drawImage(im, 0, 0, this);
}Then where you are maipulating your graphics you would do something like this:
//code snippet
Graphics g = im.getGraphics();
//make what ever changes to im by manipulating the graphics context g
repaint();

Similar Messages

  • Moving GIF images

    Hi
    Earler I had Golive and could make moving GIF images in a timeline. Can ayone tell me how it works in Dreamweaver CS4?
    ...from the beginning..
    Sten, Boras, Sweden

    In Java you need to override the paint method in AWT and paintComponenet method in SWING to do graphics/animation. If you go to an offscreen rendering, then you can paint to the graphics context of an image you use for a drawImage in your paint/paintComponent...
    If you where overriding a Panel in AWT you would override paint:
    public void paint(Graphics g){
      g.drawImage(im, 0, 0, this);
    }Then where you are maipulating your graphics you would do something like this:
    //code snippet
    Graphics g = im.getGraphics();
    //make what ever changes to im by manipulating the graphics context g
    repaint();

  • Drawing multiple .gif images

    Hello, I am creating a Card class and a Deck class, and I have .gif images for each card. I am trying to create a CardDisplay class to test my images. The Card/Deck classes work fine, but I am running into problems getting the images to display. What I have is a JFrame and I use a JLabel for each .gif image. When I add the JLabel to the contentPane, it is still only showing a blank window. Can someone give me any guidance as to how to go about this? Also, I am assuming once I get it to display 1 gif, it will display the remaining 51 in the same place. What I am trying to do is to display them all in a row.. well 4 rows of 13 cards that is. Thanks in advance,
    dub stylee

    Also, just wanted to add that this is not for school. I am doing this for a personal exercise using swing components. I made a card game when I was taking java 1 class, but now I am trying to familiarize myself with the use of graphics. Thanks to anybody who can help.
    dub stylee

  • Drawing on top of a gif image.

    I need to be able to have a JPanel that holds a .gif image, have another JPanel over top of it that can be drawn upon. An example of this is placing a map on a table and laying a piece of clear plastic over top of it, then drawing on the plastic the route you want to take. Just as in this example, I want to be able to erase lines on the top image, but I can probably figure that part out OK, I just need the code to layer the drawing panel on top on the image.
    How can this be done?
    Thanks.

    Exactly what problem are you having with getting a layered pane? The Java Tutorial on this site can give you all the basics regarding setting one up.

  • Problem at displaying animated gif images !!!!!!!!!!!!

    hello everyone......i am trying to display an animated gif image..............so till far i have no issues on this....
    but i face problem when :
    i have created a class called SimpleGame which extends JPanel....
    public class SimpleGame extends JPanel
    //code
    public void paintComponent(Graphics g)
    //code to draw image
    }now i have written another class with main method
    public class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    }so image gets displayed but only one frame of animated image......image that is displayed is static.....since it is a animated gif,,,,,so some how animation is not rendered......only one frame is displayed......
    why is it happening ??
    if i try to display animated image from a single class i mean my paintComponent method and main method is at same class then i do not face problem.....
    but if my paint method is in another class and i am using that method from another class then animation does not get rendered.........
    any help !!!!! please...........

    class SimpleGame extends JPanel
    Image img=new ImageIcon("y.gif");
    public void paintComponent(Graphics g)
    g.drawImage(img,150,150,this);
    }main class//
    class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    public static void main(String[] args)
    new MyGame();
    }my image gets displayed.......but only single frame of a animated image....animation is not happening..........

  • Animated gif images not working, n73 problem pleas...

    my phone is n73music. when i try to use animated or gif images as wallpapers, the images are not moving as they should do in standby mode on the display. what could be the problem, please advice. thankyou.

    Sorry, N73/ME is a s60 phone and s60 doesnt support moving animated GIG, PNG file format as wallpaper

  • Problem with Gif image

    Having a problem with gif image not showing up. It will show up in netscape6.2, but not in IE 5.0. Both are using the java 1.4 plugin. They are basic buttons (zoom in, zoom out, etc) and they actions work, just the icons aren't showing. Any help would be great! Below is a snip of code:
    JPanel toolBarsPanel = new JPanel();
    javax.swing.JToolBar toolbar = new javax.swing.JToolBar();
    JButton zoomin = new JButton(new ImageIcon("tut/zoomin.gif"));
    JButton fullext = new JButton(new ImageIcon("tut/fullextent.gif"));
    JButton identify = new JButton(new ImageIcon("tut/identify.gif"));
    JButton btn = new JButton(new ImageIcon("tut/addtheme.gif"));
    toolbar.add(zoomin);
    toolbar.add(fullext);
    toolbar.add(identify);
    toolbar.add(btn);
    add(toolbar, BorderLayout.NORTH);
    Thanks again for any help!

    I used to do a lot of work in this sort of thing. After a while we were able to convince our bosses to use generated HTML (JSPs, etc.), so the problem moved to porting JavaScript to different platforms! (Platforms in this context means the different browser/OS combinations, etc.).
    The only two things I can recommend are:
    - complete control over you code. You will have to fix it! (Tried you apps on a Mac yet?)
    - assume a minimal install. Don't assume users are going to have any fancy tools installed on their PC, unless you are developing an Intranet app, where you know the spec of the machines that are going to be using it.
    As regarding getting IE to use a relative address, I don't think you are going to have any luck their, I'm afraid! (Although I am curious. It has been some time, but I though it did use relative addresses. Are you absolutely sure about this, did you check this out with System.outs and that?
    HTH,
    Manuel Amago.

  • BufferedImage doesn't draw every gif

    hi all,
    I create a buffered Image which should show 2 different gifs (not animated). my problem is that it draws only one of them. I don't think that it has to do with the gif itself because I tried the same drawing without buffering and everything could be seen.
    private BufferedImage bufferedBG;
    setBG();
    private void setBG() { 
    Image linieH = getToolkit().getImage(getClass().getResource("img/bg_linieH.gif"));
    Image linieV = getToolkit().getImage(getClass().getResource("img/bg_linieV.gif"));
    setBackground( Color.WHITE );
    bufferedBG = new BufferedImage( 676 + OFFSET_X, 578, BufferedImage.TYPE_INT_ARGB );
    Graphics2D g = bufferedBG.createGraphics();
    g.drawImage(linieH, 100,200, this);
    g.drawImage(linieV, 150,300, this);
    public void paint( Graphics g ) {
    Graphics2D g2 = (Graphics2D) g;
    g2.drawImage( bufferedBG, null, 0, 0 );
    any ideas?
    thanks
    gammloop

    I strongly suspect that what we have here may be confusion about user space and device space..
    The Graphics2D instance in your image class DOES NOT share coords with your paint(Graphics g)
    instance! Its x, y start is 0, 0 and bears no relation to the position on-screen of the component you are
    trying to paint...

  • Please, Please Help Me (.gif Images)

    Hello,
    I want to cry, I've been trying to include .gif images in my swing applications but am having big problems. I've been reading the forums and trying everything. If I try the most basic of examples just to get it working I still have problems. The code compiles correctly and the panels appear but no pics. I've tried including every different file path version, moving .gifs to different folders, what is the problem, why no pics. I'm running J2SE v 1.4.1_02, please help, I would be so greatful, don't make me cry,
    Lucy
    import java.awt.*;
    import javax.swing.*;
    public class JFrameImage extends JFrame
    public JFrameImage()
    Container c = getContentPane();
    JPanel panel = new JPanel()
    public void paintComponent(Graphics g)
    ImageIcon img = new ImageIcon("globe.gif");
    g.drawImage(img.getImage(), 0, 0, null);
    super.paintComponent(g);
    panel.setOpaque(false);
    ImageIcon icon = new ImageIcon("cat.gif");
    JButton button = new JButton(icon);
    panel.add(button);
    c.add(panel);
    public static void main(String[] args)
    JFrameImage frame = new JFrameImage();
    Image onFrame = Toolkit.getDefaultToolkit().getImage("icon.gif") ;
    frame.setIconImage(onFrame);
    frame.setSize(200,200);
    frame.setLocation(300,200);
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.setVisible(true);

    sorry but I think it should be something else.
    To locate a File you need it's full name, including the extension. Maybe since the extension wasn't showing it's actual filename was cat.gif.gif? I don't know. Anyway, this is a method I use for all my image retrieving, just put it in some Util-class:  private static HashMap hmImages = new HashMap();
      public static ImageIcon getImage (String name)
        if (hmImages.containsKey(name))
          return (ImageIcon) hmImages.get(name);
        String url = System.getProperty("user.dir") + "/resources/" + name;//or any other directory were all your image-files are under (even in subs, in that case add the subdirectory to the arg name
        try
          ImageIcon ic = new ImageIcon (url);
          if (ic != null)
            hmImages.put(name, ic);
            return ic;
        catch (Exception e)
        System.out.println("Warning: image '" + url + "' not found");
        return null;
      }greetz,
    Stijn

  • How to resize a gif image

    hi
    i need to resize a gif image to my preferable height and width . i have copied some code from net , its working fine for small images . but when i resize large images the background becomes back .... so
    any body help me put in this....
    regards
    mano

    hi
    thanks for ur reply . can u plz tell me were to insert the code here
    Image image = Toolkit.getDefaultToolkit().getImage("C:\\image.gif");
    MediaTracker mediaTracker = new MediaTracker(new Container());
    mediaTracker.addImage(image, 0);
    mediaTracker.waitForID(0);
    // determine thumbnail size from WIDTH and HEIGHT
    int thumbWidth = Integer.parseInt("120");
    int thumbHeight = Integer.parseInt("75");
    double thumbRatio = (double)thumbWidth / (double)thumbHeight;
    int imageWidth = image.getWidth(null);
    System.out.println("imageWidth "+ imageWidth);
    int imageHeight = image.getHeight(null);
    double imageRatio = (double)imageWidth / (double)imageHeight;
    if (thumbRatio < imageRatio) {
    thumbHeight = (int)(thumbWidth / imageRatio);
    } else {
    thumbWidth = (int)(thumbHeight * imageRatio);
    // draw original image to thumbnail image object and
    // scale it to the new size on-the-fly
    BufferedImage thumbImage = new BufferedImage(thumbWidth,
    thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
    // save thumbnail image to OUTFILE
    BufferedOutputStream out = new BufferedOutputStream(new
    FileOutputStream(args[1]));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.
    getDefaultJPEGEncodeParam(thumbImage);
    int quality = Integer.parseInt("75");
    quality = Math.max(0, Math.min(quality, 100));
    param.setQuality((float)quality / 100.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(thumbImage);
    out.close();
    System.out.println("Done.");

  • Changing speed of moving gif

    I currently have some java code that displays a moving gif file i.e. a gif file that has several images in it that are shown in a timed sequence and can give the illusion that the picture is moving if animated correctly.
    Anyway I use
    logo1 = new ImageIcon("magic.gif" );
    to get the image and latter use a method that displays it.
    My question is basically I was wondering if there is any other method I can use to slow the gif file down.
    Otherwise I am going to have to edit the gif image itself by using some image manipulation software which I currently don�t have.
    Any idea if this is possible.
    Thanks

    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.FileImageInputStream;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    * @author Ian Schneider
    public class AnimatedGIF {
        public static void main(String[] args) throws Exception {
            ImageIcon icon = new ImageIcon();
            javax.swing.JFrame f = new javax.swing.JFrame();
            f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
            f.getContentPane().add(new JLabel(icon));
            f.setVisible(true);
            ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
            reader.setInput(new FileImageInputStream(new File(args[0])));
            for (int i = 0; i < reader.getNumImages(true); i++) {
                BufferedImage image = reader.read(i);
                icon.setImage(image);
                f.pack();
                f.repaint();
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ioe) {
            System.exit(0);
    }

  • Transparency gif image for icon

    Hi all,
    I am trying to do some art work with Microsoft paint. I am trying to draw an icon(a gif image).
    Microsoft paint? Is there any other tool that I can use?
    I have problem with the transparancy color. It keep showing up even I set the color to be RGB(153,153,153) Any idea guys?
    Thanks

    In my experience, if there is a GIF image that already contains transparent pixels, you can show it using "ImageIcon.class" directly without the need to set any RGB color yourself.

  • Servlet to generate JPG/GIF image

    I've got sth like that:
    response.setContentType("image/gif");
    OutputStream out = response.getOutputStream();
    Image messageImage = makeMessageImage(message, fontName, fontSize);What I should do next to send it to the browser and display it?

    You can create a BufferedImage, draw messageImage onto it, and then send the BufferedImage through the OutputStream via
    ImageIO.write(theBufferedImage, "gif", out); Or if messageImage is already a BufferedImage, then you can just send it directly after casting it.
    There's a slight complication, however. The GIF format uses palette-based images. If you send an image that's not palette-based then it will use the default palette. It's the same as if I had created this
    BufferedImage theBufferedImage = new BufferedImage(
            messageImage.getWidth(null),
            messageImage.getHeight(null),
            BufferedImage.TYPE_BYTE_INDEXED); drew messageImage onto it and then sent it. The default palette almost certainly isn't the 256 most representative colors in your message image. This may or may not be a problem. I don't know the kind of quality you want. If your image doesn't have any color, a viable alternative is TYPE_BYTE_GRAY.
    Ideally, for a full-colored image you would create an IndexColorModel of what you feel is the 256 most representative colors in the image. Then you would create a BufferedImage using this palette, draw the original image onto it, and send it off.

  • Error while loading a logo .gif image to the banner

    Hi all,
    I'm running Portalea on NT platform and I receive the following error, trying to load a gif image as a logo to the banner (this is in spanish but I hope you can understand it):
    Wed, 27 Dec 2000 07:03:25 GMT
    ORA-06510: PL/SQL: excepcisn definida por el usuario no tratada
    ORA-06512: en "PORTAL30.WWDOC_DOCU_BRI_TRG", lmnea 60
    ORA-06510: PL/SQL: excepcisn definida por el usuario no tratada
    ORA-04088: error durante la ejecucisn del disparador 'PORTAL30.WWDOC_DOCU_BRI_TRG'
    DAD name: portal30
    PROCEDURE : PORTAL30.wwptl_banner.savecustom
    URL : http://ORACLE1:80/pls/portal30/PORTAL30.wwptl_banner.savecustom
    PARAMETERS :
    ===========
    ENVIRONMENT:
    ============
    PLSQL_GATEWAY=WebDb
    GATEWAY_IVERSION=2
    SERVER_SOFTWARE=Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.22
    GATEWAY_INTERFACE=CGI/1.1
    SERVER_PORT=80
    SERVER_NAME=ORACLE1
    REQUEST_METHOD=POST
    QUERY_STRING=
    PATH_INFO=/pls/portal30/PORTAL30.wwptl_banner.savecustom
    SCRIPT_NAME=/pls
    REMOTE_HOST=
    REMOTE_ADDR=192.168.100.224
    SERVER_PROTOCOL=HTTP/1.1
    REQUEST_PROTOCOL=HTTP
    REMOTE_USER=
    HTTP_CONTENT_LENGTH=6443
    HTTP_CONTENT_TYPE=multipart/form-data; boundary=---------------------------7d02753210f0280
    HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)
    HTTP_HOST=oracle1
    HTTP_ACCEPT=application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-comet, */*
    HTTP_ACCEPT_ENCODING=gzip, deflate
    HTTP_ACCEPT_LANGUAGE=es
    HTTP_ACCEPT_CHARSET=
    HTTP_COOKIE=portal30=AB515A5F55262E576590647AC04D98A8EF1D5A6F56D19ECCD710BDB4A08D2354903C0CA288FDE0C9283E116C71C00B1B3821CEAB7A24979CFF326F4979143EE1FD147BC097C2AD7705313C93DAB32D8 4A6CF71C26B267CC0B2FEA03B385A2E84; portal30_sso=7452540140821A6010973F5CAC7E7D17C7498F309E15C228015C1C0546A702F5AFDE500B69BDCB8DE5C29DD726FC8DEEE85A1DC979ECC7B8A6A16CADEF1DAB0C0ACEC11897D5B99B1033884D61307BEA7AE581C 8AB988C8CBBBDCE6174BA01F6
    Authorization=
    HTTP_IF_MODIFIED_SINCE=
    null

    Hi,
    No errors was found in the installation log. I'm looking in the WWDOC_DOCUMENT$ table and found records that make references to my previous tries to upload the logo image. In order to make others tries, how can I delete this information? Are references to this files in any other table?.
    I'm looking over the solution provide by Laurent Baresse, refering to the NLS_LANGUAJE problem ... (Thanks Laurent).
    Best regards
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Karthika Siva ([email protected]):
    Fernando,
    Are you able to upload any documents into a content area? Please look at your installation log file (install.log) for any errors that may have occured during the installation of the product. Also make sure that the tablespace containing the WWDOC_DOCUMENT$ table is not full.
    Karthika<HR></BLOCKQUOTE>
    null

  • Animated Gif Image does not render correctly on screen

    I have added animated gif image to the scene it does not render correctely.it shakes on the screen. plz give me any suggestion
    i use following code
    Image logo= new Image(getClass().getResourceAsStream("images/image.gif"));
    logoLabel.setGraphic(new ImageView(logo));

    Hello user,
    I think gif are rendered smoothly.
    Are you sure you are not making many object of same images everytime?
    Thanks.
    Narayan

Maybe you are looking for