Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5997805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:18:58+00:00 2026-05-23T00:18:58+00:00

Hey everyone, So, I’m currently trying the implement the APNG Specification , but am

  • 0

Hey everyone,
So, I’m currently trying the implement the APNG Specification, but am having some trouble with the frame rendering. My function is

    private void UpdateUI()
    {
        foreach (PictureBox pb in pics)
        {
            APNGBox box = (APNGBox)pb.Tag;
            APNGLib.APNG png = box.png;
            if (box.buffer == null)
            {
                box.buffer = new Bitmap((int)png.Width, (int)png.Height);
            }
            APNGLib.Frame f = png.GetFrame(box.frameNum);
            using (Graphics g = Graphics.FromImage(box.buffer))
            {
                switch (f.DisposeOp)
                {
                    case APNGLib.Frame.DisposeOperation.NONE:
                        break;
                    case APNGLib.Frame.DisposeOperation.BACKGROUND:
                        g.Clear(Color.Transparent);
                        break;
                    case APNGLib.Frame.DisposeOperation.PREVIOUS:
                        if (box.prevBuffer != null)
                        {
                            g.DrawImage(box.prevBuffer, Point.Empty);
                        }
                        else
                        {
                            g.Clear(Color.Transparent);
                        }
                        break;
                    default:
                        break;
                }
                Bitmap read = png.ToBitmap(box.frameNum++);
                switch (f.BlendOp)
                {
                    case APNGLib.Frame.BlendOperation.OVER:
                        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                        break;
                    case APNGLib.Frame.BlendOperation.SOURCE:
                        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                        break;
                    default:
                        break;
                }
                g.DrawImage(read, new Point((int)f.XOffset, (int)f.YOffset));
            }

            box.prevBuffer = box.buffer;
            pb.Image = box.buffer;

            if (box.frameNum >= box.png.FrameCount)
            {
                box.frameNum = 0;
                box.buffer = null;
                box.prevBuffer = null;
            }
        }
    }

The APNGBox is

internal class APNGBox
    {
        public int frameNum = 0;
        public APNGLib.APNG png;
        public Bitmap buffer;
        public Bitmap prevBuffer;
    }

I think that this is mostly correct, as I’ve run it against all the images in the APNG Gallery. However, some of them are rendering incorrectly (This one has artifacting issues, and this one does not retain the red bar on the left consistently). Please note, you’ll have the view the page in Firefox 3 or higher to view the animations.

I’m lead to believe the issue has to do with how I handle the DISPOSE_OP_PREVIOUS, but I can’t figure out what I’m doing wrong. Can anyone suggest what I might be missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:18:59+00:00Added an answer on May 23, 2026 at 12:18 am

    So, I was able to figure it out in the end, and will post here in case anyone in the future comes across a similar problem. Turns out the issue was largely threefold:

    1. One should not change the ‘previous buffer’ if the frame type is ‘PREVIOUS’
    2. One should use the previous frame’s dispose_op, not the dispose_op of the current frame, to determine how it disposes
    3. One should be sure to dispose only the old frame’s region, not the whole frame

    The new code is:

        internal class APNGBox
        {
            public int frameNum { get; set; }
            public APNGLib.APNG apng { get; set; }
            public Bitmap buffer { get; set; }
            public Bitmap prevBuffer { get; set; }
    
            public APNGBox(APNGLib.APNG png)
            {
                frameNum = 0;
                apng = png;
                buffer = apng.ToBitmap(0);
                prevBuffer = null;
            }
        }
    
        private void UpdateUI()
        {
            foreach (PictureBox pb in pics)
            {
                APNGBox box = (APNGBox)pb.Tag;
                APNGLib.APNG png = box.apng;
                if (!png.IsAnimated)
                {
                    if (pb.Image == null)
                    {
                        pb.Image = png.ToBitmap();
                    }
                }
                else
                {
                    if (box.frameNum != png.FrameCount - 1)
                    {
                        Bitmap prev = box.prevBuffer == null ? null : new Bitmap(box.prevBuffer);
                        APNGLib.Frame f1 = png.GetFrame(box.frameNum);
                        if (f1.DisposeOp != APNGLib.Frame.DisposeOperation.PREVIOUS)
                        {
                            box.prevBuffer = new Bitmap(box.buffer);
                        }
                        DisposeBuffer(box.buffer, new Rectangle((int)f1.XOffset, (int)f1.YOffset, (int)f1.Width, (int)f1.Height), f1.DisposeOp, prev);
                        box.frameNum++;
                        APNGLib.Frame f2 = png.GetFrame(box.frameNum);
                        RenderNextFrame(box.buffer, new Point((int)f2.XOffset, (int)f2.YOffset), png.ToBitmap(box.frameNum), f2.BlendOp);
                    }
                    else
                    {
                        box.frameNum = 0;
                        box.prevBuffer = null;
                        ClearFrame(box.buffer);
                        RenderNextFrame(box.buffer, Point.Empty, png.ToBitmap(box.frameNum), APNGLib.Frame.BlendOperation.SOURCE);
                    }
                    pb.Invalidate();
                }
            }
        }
    
        private void DisposeBuffer(Bitmap buffer, Rectangle region, APNGLib.Frame.DisposeOperation dispose, Bitmap prevBuffer)
        {
            using (Graphics g = Graphics.FromImage(buffer))
            {
                g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
    
                Brush b = new SolidBrush(Color.Transparent);
                switch (dispose)
                {
                    case APNGLib.Frame.DisposeOperation.NONE:
                        break;
                    case APNGLib.Frame.DisposeOperation.BACKGROUND:
                        g.FillRectangle(b, region);
                        break;
                    case APNGLib.Frame.DisposeOperation.PREVIOUS:
                        if(prevBuffer != null)
                        {
                            g.FillRectangle(b, region);
                            g.DrawImage(prevBuffer, region, region, GraphicsUnit.Pixel);
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    
        private void RenderNextFrame(Bitmap buffer, Point point, Bitmap nextFrame, APNGLib.Frame.BlendOperation blend)
        {
            using(Graphics g = Graphics.FromImage(buffer))
            {
                switch(blend)
                {
                    case APNGLib.Frame.BlendOperation.OVER:
                        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                        break;
                    case APNGLib.Frame.BlendOperation.SOURCE:
                        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                        break;
                    default:
                        break;
                }
                g.DrawImage(nextFrame, point);
            }
        }
    
        private void ClearFrame(Bitmap buffer)
        {
            using(Graphics g = Graphics.FromImage(buffer))
            {
                g.Clear(Color.Transparent);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, I'm a bit new to SEO. I built a one page website
hey everyone, my code is listed below. as you can see, I have a
Hey everyone! Im pretty new to Android and I have a webView under 2
Hey everyone, I just finished up an application I've been working on for a
Hey everyone! I was wondering how the methods in Ruby that aren't called with
Hey, I have 2 classes. When I'm trying to create an XML structure from
hey every one I newbie in php and i make simple upload page and
Hey, is there any easy way to get information when user will change time
Hey, I Have three IQueryable lists which i concat together into one list to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.