Results 1 to 5 of 5

Thread: QImage getting black areas for GIF frames

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QImage getting black areas for GIF frames

    Your code reads an image imageCount() + 2 times. I expect the last two images are the problem children.
    Qt Code:
    1. QImage* image = new QImage();
    2. QImageReader* reader = new QImageReader(gif);
    3. reader->read(image);
    4.  
    5. for(int index=0;index<=reader->imageCount();index++)
    6. {
    7. reader->jumpToNextImage();
    8. reader->read(image);
    9. QString frameName = dir + '/' + QString("out%1.jpg").arg(index,5,10,QChar('0'));
    10. image->save(frameName,"JPEG",100);
    11. }
    To copy to clipboard, switch view to plain text mode 
    Line 3: reads first image in file (discarded)
    Line 5: Loop of imageCount() + 1 iterations
    Line 7: index == 0, jump to second image in file. index == 1, jump to third image...
    Line 8: returns false (ignored) on last two loops

    Try this on your problem image
    Qt Code:
    1. const QString gif("test.gif");
    2. QImage image;
    3. QImageReader reader(gif);
    4. qDebug() << "Count =" << reader.imageCount();
    5. for (int index = 0; index < reader.imageCount(); ++index) {
    6. if (reader.read(&image))
    7. image.save(QString("output%1.png").arg(index, 3, 10, QLatin1Char('0')));
    8. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to ChrisW67 for this useful post:


  3. #2
    Join Date
    Dec 2013
    Posts
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QImage getting black areas for GIF frames

    No I think that error was just introduced in the code to extract the images to a file for tests.

    However, I did look more closely and the problem is the disposal method "Previous".

    For examples see this page: http://www.imagemagick.org/Usage/anim_basics/#previous

    Using your code with the example gif with disposal method "None" (http://www.imagemagick.org/Usage/ani...anvas_none.gif), frame #3 includes frame 2,1 and 0 all on top of one another. This is correct.

    Using the gif with disposal method "Previous" (http://www.imagemagick.org/Usage/ani...anvas_prev.gif) frame #3 includes frame 2 and 1, but does NOT include frame 0. This is not correct.

    I guess as a side question, does anyone know if there are options for how qt handles the disposal method?

  4. The following user says thank you to elephant for this useful post:


Similar Threads

  1. Replies: 8
    Last Post: 13th May 2013, 14:36
  2. Dock widget allowed areas in QMainWindow
    By jpalbertini in forum Qt Programming
    Replies: 0
    Last Post: 28th January 2013, 11:36
  3. Replies: 2
    Last Post: 10th June 2011, 14:16
  4. How to make certain areas transparent with the desktop?
    By Sir Rogers in forum Qt Programming
    Replies: 5
    Last Post: 11th May 2010, 22:08
  5. QGraphicsView and adding QWidget with transparent areas
    By sting73 in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2009, 11:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.