Animated gif on createCustomCursor

Hello All,
I am trying to show an animated gif on one of my custom cursors using :
Toolkit tk = Toolkit.getDefaultToolkit();
try{
myFrame.setCursor(
tk.createCustomCursor(ImageIO.read(this.getClass().getResourceAsStream("test.gif")),new Point(15,15),"MyCursor" ) );
catch(Exception e){}But i always see a static image for that gif.
And when i try to use the same Image to show it on a JLabel something like this :
ImageIcon ii = new ImageIcon(this.getClass().getResource("test.gif"));
JLabel label3 = new JLabel(ii);I see the animated image here.
Can someone help in showing the animated gif on the customcursor.
I have tried using the below discussion for reference but it didnt help for animated images.
http://forums.sun.com/thread.jspa?threadID=267944
Thanks for your time.

Hello,
But i always see a static image for that gif.[http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#createCustomCursor(java.awt.Image,%20java.awt.Point,%20java.lang.String)]
Note that multi-frame images are invalid and may cause this method to hang.--------
Here is another approach:
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
class AnimatedCursorTest {
  private javax.swing.Timer animator;
  private JButton button;
  private Toolkit tk    = Toolkit.getDefaultToolkit();
  private Cursor[] list = new Cursor[3];
  private URL url00 = getClass().getResource("32x32_00.png");
  private URL url01 = getClass().getResource("32x32_01.png");
  private URL url02 = getClass().getResource("32x32_02.png");
  private Point p   = new Point(0,0);
  public JComponent makeUI() {
    list[0] = tk.createCustomCursor(tk.createImage(url00), p, "00");
    list[1] = tk.createCustomCursor(tk.createImage(url01), p, "01");
    list[2] = tk.createCustomCursor(tk.createImage(url02), p, "02");
    animator = new javax.swing.Timer(100, new ActionListener() {
      private int counter = 0;
      public void actionPerformed(ActionEvent e) {
        button.setCursor(list[counter]);
        counter = (counter<list.length-1)?counter+1:0;
    button = new JButton(new AbstractAction("Start") {
      public void actionPerformed(ActionEvent e) {
        JButton b = (JButton)e.getSource();
        if(animator.isRunning()) {
          b.setText("Start");
          animator.stop();
        }else{
          b.setText("Stop");
          animator.start();
    button.setCursor(list[0]);
    JPanel p = new JPanel(new BorderLayout());
    p.add(button);
    p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    return p;
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() { createAndShowGUI(); }
  public static void createAndShowGUI() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new AnimatedCursorTest().makeUI());
    frame.setSize(320,240);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

Similar Messages

  • Toolkit.createCustomCursor(...) blocks when provided with an animated GIF

    Hi everyone:
    Here is a code snippet from an application of mine:
    // Loading an image: works fine. duke.gif is an animated Duke icon found in the source code version of J2SDK 1.3.1.
    ImageIcon imageIcon = new ImageIcon("duke.gif");
    // Conversion into an image: works fine too. I checked its proper termination with a MediaTracker, which I removed after determining that getImage() does not block at all.
    Image image = imageIcon.getImage();
    // This method blocks forever!
    Cursor myCursor = Toolkit.getDefaultToolkit.createCustomCursor(image, new Point(0, 0), "Duke");After testing with a few other GIF images, I could determine that this blocking problem seems to occur only with animated GIF images. Are animated GIFs supported as cursor images at all? Also, what is the best method to use the Toolkit.getBestCursorSize(...) to properly size the loaded image for use as a cursor icon?
    Thanks in advance for helping...
    Jean-Fran�ois Morin

    I think the problem may be that your using an animated gif. If you read the doc on the Curson class it says that Cursor is a bitmap representation of the mouse cursor. Bitmaps do not generally support animation. Also it is likely the createCustomCursor method is waiting for a call to ImageConsumer.imageComplete(). I am not sure, but if the GIF animation loops this function may never get called. This could cause your hangup. I would suggest trying a non-animated GIFf produced from the same program to ensure that your paint program is producing compliant GIFs. If that works I would assume the problem is that Cursor does not support animation at this time. I could be wrong about that, but there is nothing in the documentation to indate that it would.
    NoOneLeft

  • Open and edit animated .gif while preserving frame timing

    CS4 Premium Design Edition, Win XP
    I was disappointed with the removal of Image Ready from CS3 because although some of the functionality was placed into Photoshop 10, there was no way to open and edit an existing animated .gif while preserving the timing of each individual frame. I was told on the PS forum at the time that I really needed to use Fireworks. I resented that, because I was very happy with Image Ready and I didn't want to have to learn a new application just to gain functionality that had been included in previous versions of PS/IM.
    I've now got CS4 Premium Design Edition which of course includs Fireworks... and here's what Help has to say on the subject of imported .gifs.
    "Note: When you import an animated GIF, the state delay setting defaults to 0.07 seconds. If necessary, use the States panel to restore the original timing."
    This is no use to me. What if I don't know the individual frame timings? What if there are 200 frames with varying timings?
    Simple question: which current Adobe product is capable of importing a .gif while retaining the frame timings? If anyone knows, or if I've misunderstood the nature of the Fireworks Help quote above, I'd really appreciate some input here. Thanks :)
    Not so simple question: why was an excellent gif-editing application thrown out to have its functionality partially replaced by a bunch of scripts and half-effective workarounds cooked up by desperate users ("import a gif by using the video import and typing *.* into the filename box..")? It's a fair question I think.
    Mark

    Hi Bob, that's not glib at all, it's a reasonable question.
    I uninstalled it along with everything else when I installed CS3, in the reasonable expectation that whatever replaced IR would be at least equal in functionality.
    Perhaps I should just dig out CS2 and install IM from there, but I have some serious reservations about doing so, because I don't know if/how a partial install of CS2 will impact upon my installation of CS4, and I'm not confident of getting support.
    I am also curious to know if/why Adobe actually removed basic functionality without replicating or replacing it in their other software. I really want to know: which recent, currently supported Adobe product
    should I be using in order to regain this functionality? Or do Adobe no longer produce a geniuinely comprehensive .gif-editing application?
    Mark

  • Animated GIF ignoring frame timing

    I am trying to create simple animated GIFs with a few layers
    of text that simply fade in and fade out in sequence. My initial
    attempt worked perfectly. Most frames use the default 7/100's of a
    second delay as they fade. A few frames were manually set to much
    longer delays so that the text pauses, before fading out to be
    replaced by the next text.
    When I reopened the file, to adjust the background color, and
    then re-saved it, the GIF now plays straight through, ignoring the
    timing of each frame. Nothing I do now can get it to pause on the
    appropriate frames. I've tried cutting the symbols out and pasting
    them into a new file, removing the animation from the symbols and
    reapplying it, etc.
    Any ideas, anyone?
    Thanks in advance.

    None, None.

  • Edit animated gif

    Hi,
    How can I edit an animated gif in Photoshop Elements 6 for Mac?
    When I open the file there is just the first frame in one layer - no other layers available.
    Thanks!

    Thanks Barbara!
    Barbara B. wrote:
    ... then bring it to PSE.
    I can't drag the single frames from Preview to PSE, because PSE 6 doesn't run in window mode.
    (Is this improved in the current version?)
    I can only drag the single frames to the desktop (as TIFF files, I guess transparency info is lost then?).
    Barbara B. wrote:
    ... there's a bug beginning in PSE 6 where you can't change the frame delay rate from the default when you save an animated gif.
    What's the default frame delay rate? Maybe it's just what I need.
    Barbara B. wrote:
    You might  want to look into a free program like giffun from stone.com instead.
    Yes that's maybe a better idea. It doesn't have to be free software. Can you recommend something good?
    Thanks again!

  • Can i open and edit animated GIF in Adobe Photoshop Touch?

    Can i open and edit animated GIF in Adobe Photoshop Touch?

    No, only regular static GIF images are supported. The desktop version of Photoshop does support this however.

  • Animated GIFs are ridiculously large - why?

    Hi all,
    I cannot figure out why the animated GIFs I am exporting are
    so massive in file size. For example, I import a small 5-frame
    650Byte GIF. I edit the size of the canvas to pad it to a square
    (from 54x40 to 54x54, or something like that), then I save it with
    the following settings:
    Animated GIF
    Exact Palette
    0 Loss
    4 Colours (5 including alpha channel)
    No dither
    And it comes out as 64.4KB. How can the file size increase by
    100 times with barely any change? Even if I import it, change
    nothing and save the file with the same settings as above, it's
    still 64.4KB. Is Fireworks padding the file with unnecessary
    information or something?
    Thanks for any help,
    John.

    > But the original image is an animated GIF and it's less
    than 1KB big! So
    > how
    > does it increase in size 100 times when I save it
    even if I don't
    > change
    > anything about the image before saving? There is no
    PNG file but I can
    > link
    > you to the original 650 Byte Animated GIF:
    I'm confused. What is this I am looking at. What have you
    done to it to
    make it increase in weight?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Quircus" <[email protected]> wrote in
    message
    news:g6fohk$mip$[email protected]..
    > But the original image is an animated GIF and it's less
    than 1KB big! So
    > how
    > does it increase in size 100 times when I save it
    even if I don't
    > change
    > anything about the image before saving? There is no
    PNG file but I can
    > link
    > you to the original 650 Byte Animated GIF:
    >
    >
    http://www.aotplaza.com/Prod.gif
    >
    > Is it something to do with my settings perhaps? Like
    telling it to save
    > extra
    > information in the file?
    >

  • Animated gifs in PS CS6

    Hi all, I am trying to save animated gifs from PS, I can get it to work fine when the layers are just flat layers, but I need to create the animated gif when I have layer folders... Ie layer 1 will have a graphic and some text, layer 2 different graphic and different text. But I have to create lots of banners each with a slight change on the text. So I want to keep the text editable so its quick to just chnage the text and then save another animated gif. But when I try and create frames from layers its bringing all the bits from the layer as different frames ie the graphic is one frame then the text is one frame etc. Is it possible to create the animated gif while still having layer folders or does it just work if they are flat layers?

    Hi thanks for the reply, i didnt think it was really working, but now I have had a play, it does work and its pretty easy to change the text, it does pop open another photoshop file to edit the text, but it works ok.
    Thanks

  • Importing .GIF into Fc will not play the animated gif in output

    I imported a animated .gif  (attached video.gif) into Fc (of a sequence of pics I took saved as an animated .gif)
    It inported as a "bitmap image" and upon export to swf it did NOT show the .gif as an animated .gif but just shows the first frame..
    (It did not put this file into an assests folder...)
    So I converted the "bitmap image" into an optimaized graphic...and NOW it DOES put the original animated gif into the "assets" folder with a Graphic1.fxg and video.gif in that folder.. and If I open the gif in the assest folder it plays it as the animated .gif it is..
    BUT SADLY upon export to SWF it still DOES not play the gif as an animated gif.. just the first frame...
    Can I do anything in the code to tell the swf file that is exported to play the gif in the assest folder as an animated gif not just show the frame?
    I did the animated gif approach becasue I setup a photoshop cs4 file with a quicktime video as a layer and Fc only brought in the first frame of the quicktime layer..
    Could the next beta of Fc include the ability to import and play animated gifs as artwork as well AND/or to import Ps Cs4 video layers as videos
    So I would have to created a video page in flash pro and import that as a object? into a state?
    (no experience with flash pro but just bought cs4 and will try to learn FlashPro overweekend)

    Interesting. I don't think this is somethign you can do in Flash Catalyst. We have .GIF support in the Flash Player but I don't think you can use a GIF asset inside Catalyst. If you need that GIF to play you'll have to embed it using Flash Builder.
    But Flash Catalyst will support video version 1.0. I don't think you can turn arbitrary layers into "video" layers but you can bring in video files (like .FLV) and then attach components to behaviors (like play, stop, etc).
    =Ryan
    [email protected]

  • Load/import images into layers to create animated gif in PE4

    I'm trying to make an animated gif using Photoshop Elements 4.0.
    I have numerous images (photos) that I need to insert into separate frames of one image.
    (photo1, photo2 ..... photo10 - all combined in layers to create the frames of the animated gif)
    I can open each photo separately, copy it, go the the animated gif image, create a new layer, and paste the image into the layer to create a frame in the animated gif.  This is very time consuming.
    Does Elements 4.0 allow for just opening/importing the separate images (photos) into the layers (frames) of the gif direclty?  I remember having software that came with Macromedia Dreamweaver 4.0 in 2000 that made this simple and straight forward.

    We are not the right people to ask.  The Touch forum (for tablet) is at
    Adobe Photoshop Touch for tablet
    There's a long list f video tutorials here, but I can't see anything about animation
    Learn Photoshop Touch | Adobe TV

  • How can I make a transparent animated gif?

    I'm using CS2. I have an animated gif that I want to take the black background out of so that the animated part of it is all that remains.
    Here is a link to the image:
    http://img.photobucket.com/albums/v97/tragicmike/random/Tesseract.gif
    I basically want to remove all of the black background from the image so that the animated tesseract is all that remains. I know how to open the gif to expose the layers using ImaegeReady, then edit them in PhotoShop. But when I made the black areas of each layer transparent (by selecting the RGB channel, inverting the selection, and hitting delete), saved a copy, and tried viewing it, it seems to just display all of the transparent layers constantly instead of cycling through them.
    Can someone please help me figure out how to make an animated gif with a transparent background? If I lose some of the black areas of the animated part (since they seem to get deleted when I remove all of the black background) it's no big deal. I just need to know how to do this so that it plays correctly.
    Thank you!!!
    Mike

    &gt;
    <b>"I have to wonder why the black background was included on every frame of the moving shape."</b>
    <br />
    <br />Well, George...the only reason I can think of is because it's an animated GIF, and GIFs only support one layer.
    <br />
    <br />Whatever application it was created in should have been able to render it out with a transparent BG. But I suppose the creator had his/her reasons for going with the black BG.
    <br />
    <br />(Full disclosure: I ran across
    <s>that same</s> a similar animation back in December, and the version I grabbed only had the black showing through the inside of the tesseract. I opened it in ImageReady and
    <b>
    <i>added</i>
    </b> a black BG so the edges didn't look jaggedy.)
    <br />
    <br />
    <a href="http://www.pixentral.com/show.php?picture=1FgHXbj4UpXYtUVrbeah7sbqQXDR40" /></a>
    <img alt="Picture hosted by Pixentral" src="http://www.pixentral.com/hosted/1FgHXbj4UpXYtUVrbeah7sbqQXDR40_thumb.gif" border="0" />

  • Help with exporting as an animated gif

    I've created a small banner ad and need to export it as an animated gif.  The problem is, when I open the gif after exporting it, there's no animation.  The way the animation is set up is 1 frame on the main timeline, and a scrolling movie clip as the background.  There is no actionscript at all in the file.

    instead of converting your movieclip to a graphic:
    1.  copy the movieclip frames
    2.  create a new graphic
    3.  paste the frames to the graphic timeline
    4.  drag the graphic to the main timeline and remove the movieclip
    5.  extend the main timeline enough frames to reveal the graphic animation
    6.  make sure your gif publish settings are for an animated gif

  • How Do I Load An Animated GIF Into PictureBox Control From Byte Array?

    I'm having a problem with loading an animated GIF int a picturebox control in a C# program after it has been converted to a base64 string, then converted to a byte array, then written to binary, then converted to a base64 string again, then converted to
    a byte array, then loaded into a memory stream and finally into a picturebox control.
    Here's the step-by-step code I've written:
    1. First I open an animated GIF from a file and load it directly into a picturebox control. It animates just fine.
    2. Next I convert the image in the picturebox control (pbTitlePageImage) to a base64 string as shown in the code below:
                    if (pbTitlePageImage.Image != null)
                        string Image2BConverted;
                        using (Bitmap bm = new Bitmap(pbTitlePageImage.Image))
                            using (MemoryStream ms = new MemoryStream())
                                bm.Save(ms, ImageFormat.Jpeg);
                                Image2BConverted = Convert.ToBase64String(ms.ToArray());
                                GameInfo.TitlePageImage = Image2BConverted;
                                ms.Close();
                                GameInfo.TitlePageImagePresent = true;
                                ProjectNeedsSaving = true;
    3. Then I write the base64 string to a binary file using FileStream and BinaryWriter.
    4. Next I get the image from the binary file using FileStream and BinaryReader and assign it to a string variable. It is now a base64 string again.
    5. Next I load the base64 string into a byte array, then I load it into StreamReader and finally into the picturebox control (pbGameImages) as shown in the code below:
    byte[] TitlePageImageBuffer = Convert.FromBase64String(GameInfo.TitlePageImage);
                            MemoryStream memTitlePageImageStream = new MemoryStream(TitlePageImageBuffer, 0, TitlePageImageBuffer.Length);
                            memTitlePageImageStream.Write(TitlePageImageBuffer, 0, TitlePageImageBuffer.Length);
                            memTitlePageImageStream.Position = 0;
                            pbGameImages.Image = Image.FromStream(memTitlePageImageStream, true);
                            memTitlePageImageStream.Close();
                            memTitlePageImageStream = null;
                            TitlePageImageBuffer = null;
    This step-by-step will work with all image file types except animated GIFs (standard GIFs work fine). It looks like it's just taking one frame from the animation and loading it into the picturebox. I need to be able to load the entire animation. Does any of
    the code above cause the animation to be lost? Any ideas?

    There is an ImageAnimator so you may not need to use byte array instead.
    ImageAnimator.Animate Method
    http://msdn.microsoft.com/en-us/library/system.drawing.imageanimator.animate(v=vs.110).aspx
    chanmm
    chanmm

  • Disabled JMenuItem doesn show animated gif

    Hi there
    I would like to have a popup menu with actions that are enabled after they have finished with some background task taking some time. Basically this works fine for the enabling action on a shown popup. However, adding an animated gif as the icon or disabled icon does not show it in disabled state. In enabled state it works perfect. Please have a try with the sample code. You should see the disabled item for 2 secs and the icon is not showing up. After being enabled, it does. Invoking the menu again shows the animated gif in its last state left, but not moving any more.
    I guess, repaints are not done appropriately in disabled state... Any ideas how to solve that would be highly appreciated :-)
    Actually I used the icon at http://mentalized.net/activity-indicators/indicators/pascal_germroth/indicator.white.gif
    Cheers
    Daniel
    public class Main
      public static void main(String[] args)
        final JFrame frame = new JFrame();
        frame.addMouseListener(new MouseAdapter()
          public void mousePressed(final MouseEvent e)
            final JPopupMenu popup = new JPopupMenu();
            popup.add(new JMenuItem("Open..."));
            popup.add(new JMenuItem("Close"));
            final JMenuItem action = new JMenuItem("Long loading until enabled");
            action.setIcon(new ImageIcon("C:/spinner.gif"));
            action.setDisabledIcon(new ImageIcon("C:/spinner.gif"));
            popup.add(action).setEnabled(false);
            popup.show(e.getComponent(), e.getX(), e.getY());
            SwingUtilities.invokeLater(new Runnable()
              public void run()
                try
                  Thread.sleep(2000);
                  action.setEnabled(true);
                catch (InterruptedException e1)
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);
        frame.setVisible(true);
    }Edited by: daniel.frey on Apr 22, 2009 7:50 AM

    The problem is that you are causing the EDT to sleep, which means the GUI can't repaint itself. Read the section from the Swing tutorial on Concurrency to understand what is happening.

  • Problems/help with animated GIF exports

    I am an experienced Photoshop user.  I recently upgraded to CS5 (Windows) and have been attempting to produce animated gif files. 
    After reading a few tutorials on the topic, I have been able to: 
    Create a PSD with a few jpg images as layers; 
    Move the layers to the animation window; 
    Set the cycle times and optimize the animation window; and, 
    Use the Save for Web Devices dialog to create the GIF file. 
    Everything appears to be normal throughout this process.  However, the exported GIF file appears as a dark gray frame when I open it in IE, or upload it to my image hosting site. 
    Anybody else experiencing this type of problem? 
    Thanks 

    No, my Photoshop CS5 saves animated GIFs just fine, and I did just what you said.  For example (you have to click on an image here to see it animate):
    Can you post your image here?  Maybe it could be a problem with your browser not animating the image properly?  What version of IE do you use?
    -Noel

Maybe you are looking for