Using an Animated GIF/JPEGs Effectively

I have an animated GIF in an applet with around 200 frames, moving at a speed of 6 frames per second. However, when just drawing it in paint(), it looks extremely messy with the flashing. Then I tried another tack, and exported the gif as 200 jpeg files and used double buffering to draw it in a JPanel with the following code:
public void load()
     images = new ImageIcon[numImages];
     for (int i=0; i<images.length; i++)
          String num = "" + i;
          if (num.length() == 1)
               num = "00" + i;
          if (num.length() == 2)
               num = "0" + i;
          images[i] = new ImageIcon(dir + imageNm + num + ".jpg");
     setSize(getPreferredSize());
     startAnim();
public void paintComponent(Graphics g)
     super.paintComponent(g);
     if (images[currentImage].getImageLoadStatus() == MediaTracker.COMPLETE)
          images[currentImage].paintIcon(this, g, 0, 0);
          currentImage = (currentImage + 1) % numImages;
public void startAnim()
     if (animTimer == null)
          currentImage = 0;
          animTimer = new Timer(animDelay, this);
          animTimer.start();
     else if (!animTimer.isRunning())
          animTimer.restart();
public void actionPerformed(ActionEvent e)
     if (currentImage == numImages-1)
          stopAnim();
     repaint();
public void stopAnim()
     animTimer.stop();
}However, the outOfMemory Exception appears after loading approximately the first 50 stills. Any suggestions, besides having to extend the memory usage?

deltacoder, I tried what you suggested in the code below, to keep the images inside an array of 20 and to rotate them as soon as the image is displayed.
public void init()
     images = new ImageIcon[20];
     for (int i=0; i<20; i++)
          String num = "" + i;
          if (num.length() == 1)
               num = "00" + num;
          if (num.length() == 2)
               num = "0" + num;
          images[i] = new ImageIcon(dir + imageNm + num + ".jpg");
public void paintComponent(Graphics g)
     super.paintComponent(g);
     if (images[currentImage%20].getImageLoadStatus() == MediaTracker.COMPLETE)
          images[currentImage%20].paintIcon(this, g, 0, 0);
          if (currentImage < (numImages-21))
               String numStr = "" + (currentImage + 20);
               if (numStr.length() == 1)
                    numStr = "00" + numStr;
               if (numStr.length() == 2)
                    numStr = "0" + numStr;
               images[currentImage%20] = new ImageIcon(dir + imageNm + numStr + ".jpg");
          currentImage++;
}However, for some reason, it is still laggy. Can you perhaps see why from my code? must41, I am also working on your suggestion. In your thread for loading images, shouldn't there be some sleep time? Otherwise, the thread might get ahead of itself and cause outofmemory exception. And from what I know, whenever garbage collect runs, the code will run laggier than usual no matter what. Perhaps, I should have mentioned earlier, but there is also an AudioClip playing in the background (which does take up memory itself) that I like to match to the images (which i know will match because i made the animation using Flash MX), which is why I can't afford the lag from the garbage collecting.
Perhaps there is a way to combine both of your suggestions?

Similar Messages

  • Using an animated gif/other to display series of images within another image?

    I design custom baseball cards for a hobby, and am wondering if I can use an animated GIF inset within a large photo to display a rotation of images.
    It is easiest if you look at the "card"/image . . . within the circle, where there is a picture of Ruth holding some bats, I would like to add a series of several images that would rotate through (obviosuly the "card" would be for viewingonline rather than printing).
    Is it possible to do?  I am thinking an "animated gif" would be the easiest, but if there is some other way (video, etc.). I am open to that.
    I just would like to know if the goal can be done, and if so, how to do it.
    TIA!!!

    That can be done with a gif.  You just set up your bg image, then have a series of layers for your insert.  Create a frame animation by opening it in Window>Timeline.  Have all your insert layers except one turned off.  Create a new frame, the turn on the next layer.  Keep repeating creating a new frame and turning on a new layer.  When you're done, you can set the time each frame displays.  Save it using save for web using the gif option.

  • How to use an animated .GIF image as the texture in Cp4 ?

    Hello all
    I wish to create an animated banner and use it as the texture in Captivate 4.
    As I know texture supports only image formats( JPEG, PNG, GIF,etc). So, I have created a small animation in Photoshop and saved in GIF format and used it as the texture. But when I preview the movie it is displayed as an image but not the animation.
    Is there any solution for this problem?
    Kind regards,
    Kartik Pullela

    1. Instal this package: http://nugetmusthaves.com/Package/WpfAnimatedGif2. Use the code below:
    <Window x:Class="WpfAnimatedGif.Demo.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:gif="http://wpfanimatedgif.codeplex.com"Title="MainWindow"Height="350"Width="525"><Grid><Image gif:ImageBehavior.AnimatedSource="Images/animated.gif"/></Grid>I found this on: http://wpfanimatedgif.codeplex.com/, and this is the useful solution because <MediaElement /> doesn't show the .gif image, and that's pretty strange.

  • Can I use an animated GIF with Keynote 6.0?

    I'd like to loop the animation of an animated GIF in my keynote presentation.
    Used to be possible with the Quicktime inspector...
    Is this possible in Keynote 6.0 ?
    Cheers, Juergen

    Easy work-around is to rename your file with .mov extention (I used myanimatedimg.gif.mov), drag the file from finder and Keynote now thinks its a movie. You now have the movie controls on the right which all work perfectly for your annimated gif!

  • I'd like to use an animated gif as a hover state to a static logo

    Does anyone know if this is possible, and if so, how do I do it?

    I am trying to animate a rocket taking off. Here is the test page I am working on. You will see 3 rockets.
    The one on the left has a rollover state with the animation playing once but then it will not play again when you rollover it.
    The middle rocket has a rollover state as a looping gif. Not the desired effect.
    The one on the right is just a static version.
    http://rockettestgt.businesscatalyst.com/index.html

  • Possible to Use Animated GIF as Rollover Image?

    Before I spend a lot of time on development...does anyone
    know if it's possible to use an animated GIF as a rollover image in
    Captivate? I'm developing an e-Learning course for a
    Sarbannes-Oxley application, and I want to be able to hover over an
    object, then have a rollover graphic describe the hover target in
    more detail...the catch being that I want the description to look
    like a scrolling stock ticker.
    I'm sure Flash is probably the ideal development environment
    for this idea, but that project is way beyond my Flash skills at
    this point...
    Thanks!

    I know you can load and display a PNG image just the way you do for a GIF/JPEG one :
    ImageIcon myIcon = new ImageIcon("my_icon.png");but I don't think many others formats are recognized by j2se... you can simply try to load a BMP file to find out.

  • Using animated GIF as JButton icon

    Hi,
    I am trying to use an animated gif as an icon in a JButton.
    Everything works as it should except the animation is static!!
    Screenshots and code are at:
    http://www.beammicrosystems.com/Java/JButton.html
    Anyone got any good ideas?
    Regards,
    Andrew

    well i think you can do this in a label you can watch for a animation like you want a gif so my idea is that you should just make the label as a button and them :
    JLabel label = new JLabel();
    label.setIcon = new ImageIcon("name.gif");
    and put it the setBounds
    label.setBounds(x,y,long,tall);
    and if you want that looks like a button just do this
    label.setBorder(BorderFactory.createRaisedBevelBorder());
    thats all.

  • Animated GIF loop problem

    I have created a simple roll over effect using an animated
    GIF over 10 frames in Fireworks which increases the fill opacity of
    a button on mouse over. I set the loop to 1 so that the animation
    will play the 10 frames and then stop, but when i export to
    Dreamweaver and preview in browser the loop will not stop.

    I think this is an oversight in functionality.
    I also was never able to get the 'stop' to work.
    h

  • Splash page with animated gif only question

    Hello all:
    I have a splash page (index.html) that is designed using an animated gif created in photoshop. The rest of my site is Css/XHTML, but has some divs containing animated gifs. I have two questions;
    1: By using only the animated gif on the splash page, am I limiting or hindering my SEO (google, microsoft, yahoo) ranking opportunities as there is no "content" on the page that the spiders/bots can see? I went ahead and included some "content" but hid it by coloring the type the same as the background color hoping that might do something, but obviously I'm a SEO newbie so any suggestions are more than welcomed. I will include the code at the end of this post, and my site is: http://reynolds-marketing.com.
    2. Is there a way to pre-load the animated gifs on my pages so that they play more smoothly and efficiently?
    TIA for any of your help. Murman
    The code for the splash page:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Reynolds Marketing - The Marketing Resource Source</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <meta name="description" content="Reynolds Marketing is a marketing services company offering a full spectrum of marketing services including: consultation, creative, production and logistical marketing services headquartered in Temecula, CA." />
    <meta name="keywords" content="Reynolds, Reynolds Marketing, marketing services company, marketing services agency, full spectrum of marketing services, full service marketing agency, marketing consultant, print creative, digital printing, offset printing, website design, website development, digital marketing, digital print on demand, DPOD,Video Production, Video Production, Direct Mail, Temecula, powerpoint presentations" />
    <link rel="shortcut icon" href="http://www.reynolds-marketing.com/favicon.ico"/>
    <!-- ImageReady Styles (index3.psd) -->
    <style type="text/css">
    <!--
    #index_ {
         position:relative;
         left:0px;
         top:0px;
         width:640px;
         height:480px;
         margin-left: auto;
         margin-right: auto;
    -->
    </style>
    <!-- End ImageReady Styles -->
    </head>
    <body bgcolor="#FFFFFF" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" id="index_" style="background-color:#FFFFFF;">
    <p>
      <!-- ImageReady Slices (index3.psd) -->
    <img src="images/index.gif" alt="" width="640" height="480" border="0" usemap="#indexMap" id="index" /></p>
    <p>Reynolds Marketing offers a full spectrum of marketing communications services including: consultation, creative, production and logistical marketing services located in Temecula, California. Our services include marketing consultation, press relations, public relations, copy writing, print creative, direct mail creative, video creative, web creative, interactive creative. Print production, direct mail, video production, web page creation and production. Digital print on demand, fulfillment services, powerpoint presentations, marketing communications, marketing communications conformance. To find out more about our services, please go to <a href="http://www.reynolds-marketing.com/who_we are.html">http://www.reynolds-marketing.com/who_we are.html</a> . </p>
    <p>Site map:<br />
      <a href="http://www.reynolds-marketing.com/index.html">http://www.reynolds-marketing.com/index.html</a><br />
      <a href="http://www.reynolds-marketing.com/who_we_are.html">http://www.reynolds-marketing.com/who_we_are.html</a><br />
      <a href="http://www.reynolds-marketing.com/contact_us.html">http://www.reynolds-marketing.com/contact_us.html</a><br />
      <a href="http://www.reynolds-marketing.com/what_we_do.html">http://www.reynolds-marketing.com/what_we_do.html</a><br />
      <a href="http://www.reynolds-marketing.com/services.html">http://www.reynolds-marketing.com/services.html</a><br />
      <a href="http://www.reynolds-marketing.com/clients.html">http://www.reynolds-marketing.com/clients.html</a><br />
      <a href="http://www.reynolds-marketing.com/projects.html">http://www.reynolds-marketing.com/projects.html</a><br />
      <a href="http://www.reynolds-marketing.com/news.html">http://www.reynolds-marketing.com/news.html</a></p>
    <p>
      <map name="indexMap" id="indexMap">
        <area shape="rect" coords="296,434,342,444" href="who_we_are.html" />
        <area shape="rect" coords="228,451,286,461" href="who_we_are.html" />
        <area shape="rect" coords="296,451,353,461" href="what_we_do.html" />
        <area shape="rect" coords="364,451,416,461" href="contact_us.html" />
      </map>
      <!-- End ImageReady Slices -->
      <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
      </script>
    </p>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-8703884-1");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    </body>
    </html>

    My guess is yes, but that is just my opinion.  I believe the text/background same color idea was really in vogue back in the late 90's and we all heard that it was the kiss of death for SEO that the SE's hated them so much you got de-listed, not sure if that is a fact or not.
    My bigger concern would be how many people you are losing by making them wait to get to where they want to go.  I have told many a client that in some sense, the interent is too big, you have too much competition and people have thin patience for things like splash pages.  The ooo and aaa effect of animated gifs is long dead...again, in my opinion.
    I dont know the answer to your load question...
    Gray

  • Problem with importing animated gifs

    Hi i'm trying to use an animated gif in my project. Basically my after effects project is just a countdown from 10 to 0 while the animated gif spins continuously during the countdown. My problem is when I use the animated gif the background it is no longer transparent and the background is instead white. How do I make it transparent again in after effects? Next the animated gif is about a 2 second loop, it won't let me drag the bars to extend the time to 10 seconds. How do I loop it for 10 seconds?
    These aren't musts, but if anyone could, help would be greatly appreciated:
    1) For the text effect 'numbers' (which I used for the countdown effect) it always renders really shaky and bouncy when i preview it. Is that normal?
    2) It has the time as 00:00:00:00 (type: timecode 30). How do I make so it only shows 00:00 ?
    Any help would be awesome.
    Thank you

    My problem is when I use the animated gif the background it is no longer transparent and the background is instead white.
    Correct. As a conmpositing program, AE requires proper Alpah transparency, not palette-based transparency. File must be converted to an image sequence with Alpha channel.
    Next the animated gif is about a 2 second loop, it won't let me drag the bars to extend the time to 10 seconds. How do I loop it for 10 seconds?
    Footage interpretation --> Loops
    1) For the text effect 'numbers' (which I used for the countdown effect) it always renders really shaky and bouncy when i preview it. Is that normal?
    Yes, it's normal if you are using a non-monospaced font. Use a suitable font.
    2) It has the time as 00:00:00:00 (type: timecode 30). How do I make so it only shows 00:00 ?
    Use multiple layers and effects and mask them out.
    Mylenium

  • How do I import animated gifs into Premiere with a transparent background?

    I have an animated gif that I got from the internet, and I'm trying to import it into Premiere Pro with a transparent background. The gif is of a video game character standing still and blinking. Whenever I import it, it always has a white background, so I need help on how to change that.
    I've gone into Photoshop and removed the white background frame by frame, making it transparent. I do this by using the magic wand tool to select the white background, then hit "delete" to turn it into that diamond grid, which means it's transparent. I then select File -> Save for Web. I preview every frame, and it shows that the backgrounds are transparent. I save it as a gif. But when I import it into Premiere Pro, the white background is still there.
    I've read many forums online about people trying to import images into Premiere Pro with a transparent background, but none of them have explained how to do it specifically for animated gifs. Every answer has always been "export the image as a png, that'll work", and sure enough, I exported a few frames of the gif as pngs, and those few frames had transparent backgrounds in Premiere Pro. But I don't want a png because those aren't animated sequences, those can only be still images. I need to export it as a gif so that it will remain animated, but gif files always have that dreaded white background in Premiere Pro.
    I suppose I could export every frame as a png, import each of those frames into Premiere Pro, then string all the frames together and tweak them so they'll be functionally identical to the animated gif, but that would take forever. I'm making a video project and I need numerous animated gifs to work with, so I don't want to do that with every single one of them. I'm looking for a way to simply import the gifs into Premiere Pro and be done with it. If there is any way to do this, please help me.
    -Robert

    faind on gif transparency and other cartoon animation problems : Adobe After Effects
    " The reason: GIFs don't support alpha channels. Instead, their file structure assigns a certain color value to be read as totally transparent. There aren't any degrees of transparency as you find in graphics formats that do support alpha channels.
    To use an animated gif in AE, you'd first have to create the areas of transparency, then convert the series of images into a graphics format that supports alpha channels, and there are a bunch: PICT, TIFF, TARGA or PNG, to name a few."

  • Putting animated gifs in a Fireworks layout: What is the deal?

    Ok I have scoured the help files.
    Im not finding what I need to know.
    I want to create a Fireworks layout with 10 squares that have photos in them that fade back and forth between one image and another, slowly.
    I would imagine I can pull this off with animated Gifs.
    Thing is, I can not figure out how to pull this off in Fireworks.
    Do I slice up my layout and make each photo square a symbol, then give it a different state and tween between them?
    And if so, how do you control that?
    Or do I make animated gifs in Photoshop and drop them into Fireworks?
    I tried this and the gif came in with 40 states and the animation looked ridiculously bad. Not smooth and way to slow.
    Is there a decent video tut on how to make animations in Fireworks.
    I havent found it yet (nothing on Adobe TV oddly)
    I have a feeling this shouldnt be that difficult but so far, it is.
    I also want to have a rollover in the same layout.
    Is this asking too much of Fireworks?

    Well, some time ago I also thought: Why not create a set of very complicated animated GIFs (using Fireworks, of course;-) and connect them to the HTML/CSS layer of the web design, and thus do with html/css and images things that are only possible with Flash and/or adavanced AJAX scripting.
    I soon realised that this is not possible -- and in certain cases, not needed at all. Animated GIFs (+ an HTML/CSS layer) cannot substitute AJAX scripting or Flash.
    Even more: Even if in some cases you can achieve a certain effect using only animated GIFs, this will be at the cost of very poor browser performance! Reason? Animated GIFs slow down browser performance, and a lot. Flash does not slow down performance in browsers so much. JavaScript doesn't slow down performance so much, too (although it depends).
    Example: Put 100 animated GIF images inside one simple html page and watch your browser slow down terribly. Put 500, and it will maybe even crash!   Even simple GIF animations sometimes slow can be seen to slow down when starting, and then at some point, their speed goes back to normal. And that's just one example...
    In some cases, Flash is the correct answer to your questions. Well, I don't like Flash much, too, but for certain tasks there are certain tools.
    Using very complicated animated GIFs instead of Flash is like using a set of 60 spoons instead one simple shovel... :-)
    Just my 2 cents...
    PS I don't create Flash content, but in the worst case, I can ask a fellow developer to help me...
    PPS I would have created a demo with very complex Fireworks GIF animations only for the sake of pure art/pushing Fw to the limits; never in production:)

  • Animated GIF frame loss

    I have an applet that has a JPanel with a JLabel in it. That JLabel was created with an ImageIcon constructor with an animated gif image. The gif has eleven frames (each with replace set) and is set to loop. When I bring up the applet the image animates through the first 7 frames then stops. I can File/Open the gif in Netscape and it looks fine - animates all images and loops. Looking at it with:
    setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION); or FLASH_OPTION
    it looks good until that 7th frame then I start to see flash of grey the size of the JLabel.
    I understand that the ImageObserver defaults to the JLabel. But I have tried directly setting it with no joy. I have also tried calling .flush() on the image with no joy. So I tried a different animated gif and it stopped on the 3rd frame (but also appears fine in a browser).
    I am on day 2 of trying to figure this out (pulling my hair out).
    I cut this down quite a bit, so there may be syntax errors.
    public class RRR extends JApplet implements RRRConsts
    public void init()
    loadImages();
    myJPanel = new MyJPanel();
    contentPane.add(myJPael);
    private void loadImages()
    try
    problemImage = loadImage(new URL(getDocumentBase(),
    "problem.gif"));
    catch (Exception e)
    { logger.log(Level.SEVERE, "Unable to load images", e); }
    private Image loadImage(URL url) throws InterruptedException
    Image image = getImage(url);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    return image;
    MyJPanel myJPanel = null;
    static Image problemImage = null;
    class MyJPanel extends JPanel implements RRRConsts
    MyJPanel()
    setLayout(null);
    setBounds(0,0,468,540);
    setOpaque(false);
    buildUI();
    private void buildUI()
    myLabel = new MyLabel();
    add(myLabel);
    private MyLabel myLabel = null;
    class MyLabel extends JLabel implements RRRConsts, ActionListener
    MyLabel()
    super(new ImageIcon(RRR.problemImage));
    }

    I just had the same problem. It seems that when using an animated gif as ImageIcon it will not be loaded compeltly if it is too large. The maximum seems to be somewhere between 60 - 70 KB.
    I managed to use a higher compression on my gifs to make them smaller, but I haven't found any general solution yet.

  • Animated GIF's as Wallpaper

    I have tried to use several animated gif images as wallpaper on my Nokia 5610, but none of them will animate, only the first frame shows (no cycling of frames). Are animated gif's not supported by the nokia 5610? Is there an option I need to turn on?

    Most Nokia phones will not support animated GIFs as wallpapers (I say most just to cover myself, I'm not sure that any do).
    You should be able to view animated images withing the gallery, but the behaviour you describe seems normal for the wallpaper.

  • Animated gif in mail are not visible after upgrade to mavericks

    Hi,
    I use a animated gif in my signature in mail. This gif was playing normally (like a animated gif) in mountain lion when I writes a new message. After upgrading to mavericks I can't see the animated gif playing. I just see the first frame. However when I send a mail to my iPad using iOS 7 the animated gif is playing normally.
    Thanx for every answer!

    I'm having this issue as well — I can no longer send animated gifs in Mail with Mavericks (10.9.0). The image retains its full image size and remains a gif format, but does not play, just sits static. This also affects forwarding animated gifs — which play fine in the mail window — they are static in the compose window and are sent static.

Maybe you are looking for

  • Connecting an IPad to WRN160N

    I am trying to connect a new IPad to my network and the Ipad will not take the network password.  Do I need to change any settings on the router?  I am using MAC filtering for security

  • Validation If unit price of GRPO is different from PO

    Hi, I  am trying to assign 1 validation for scenario mentioned in the subject. The validation which i have tried is showing me error even if i have not changed the unit price at the GRPO level. IF @transaction_type IN (N'A', N'U') AND (@Object_type =

  • Hi, i can't click on the 'Draw Inside' button

    i am unable to click on the 'Draw Inside' button at the bottom left to place a pattern into an image that i got off google, how can i place a pattern that i have made into my image?

  • How can I confirm the automatic updater of revoked certificates is working?

    There is a Microsoft security advisory from a few weeks ago about fraudulent certificates. In the advisory it says it is revoking India's NIC authority certificate and for systems running Windows 7 that are using the automatic updater of certificates

  • Itunes can not start! InpageError! HELP

    Today when I started my PC, and opened iTunes. Suddenly, it shows a windows, says; "iTunesHelper Module needs to be closed" When I clicked to close, then the whole iTunes crashed--It doesnot start anymore. Then I uninstalled iTunes, and re-installed