Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Problems with using series of PNG files as animations

Problems with using series of PNG files as animations

Scheduled Pinned Locked Moved .NET (Core and Framework)
performancetutorialhelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    ddavor
    wrote on last edited by
    #1

    Hi, I'm trying to write application where I use series of PNG files for animations. I created control which loads Images from file into ArrayList, and then on specified timer interval I change picture that I want to display. I'm using 1280x720 PNGs. I have 2 problems here: 1) My PNG is around 300KB, and when I execute Image.FromFile("my.png") memory of my process is increased for 4MB. So, if I load 30 pictures, memory will grow to around 130MBs and the problem is that I have to keep lot of images loaded into memory since I'm using it constantly during execution time. 2) performances of DrawImage functions are quite bad and I cannot get proper speed (if I need 25 frames per second for example) Does anyone have some suggestions how to solve this? Thnx in advance!

    M H 2 Replies Last reply
    0
    • D ddavor

      Hi, I'm trying to write application where I use series of PNG files for animations. I created control which loads Images from file into ArrayList, and then on specified timer interval I change picture that I want to display. I'm using 1280x720 PNGs. I have 2 problems here: 1) My PNG is around 300KB, and when I execute Image.FromFile("my.png") memory of my process is increased for 4MB. So, if I load 30 pictures, memory will grow to around 130MBs and the problem is that I have to keep lot of images loaded into memory since I'm using it constantly during execution time. 2) performances of DrawImage functions are quite bad and I cannot get proper speed (if I need 25 frames per second for example) Does anyone have some suggestions how to solve this? Thnx in advance!

      M Offline
      M Offline
      molesworth
      wrote on last edited by
      #2

      Firstly, PNGs aren't really the best way to do animations. You should maybe think about using GIF images instead.

      ddavor wrote:

      1. My PNG is around 300KB, and when I execute Image.FromFile("my.png") memory of my process is increased for 4MB. So, if I load 30 pictures, memory will grow to around 130MBs and the problem is that I have to keep lot of images loaded into memory since I'm using it constantly during execution time.

      I suspect (although I haven't tried it) that the 4MB jump is mainly a one-off overhead, and you won't get that increase on subsequent image loads. Try it and check though.

      ddavor wrote:

      1. performances of DrawImage functions are quite bad and I cannot get proper speed (if I need 25 frames per second for example)

      You're drawing a 300KB 1280 x 720 PNG image, so I'm not surprised it's a bit slow... An animated GIF will automatically play when loaded (although if you keep to that size it may still be a bit slow - again you'd need to test it) and if you can reduce the quality a bit you can probably reduce the file size to something more reasonable. Alternatively, combine the images into an AVI and use a simple AVI player to show the animation.

      There are three kinds of people in the world - those who can count and those who can't...

      D 1 Reply Last reply
      0
      • M molesworth

        Firstly, PNGs aren't really the best way to do animations. You should maybe think about using GIF images instead.

        ddavor wrote:

        1. My PNG is around 300KB, and when I execute Image.FromFile("my.png") memory of my process is increased for 4MB. So, if I load 30 pictures, memory will grow to around 130MBs and the problem is that I have to keep lot of images loaded into memory since I'm using it constantly during execution time.

        I suspect (although I haven't tried it) that the 4MB jump is mainly a one-off overhead, and you won't get that increase on subsequent image loads. Try it and check though.

        ddavor wrote:

        1. performances of DrawImage functions are quite bad and I cannot get proper speed (if I need 25 frames per second for example)

        You're drawing a 300KB 1280 x 720 PNG image, so I'm not surprised it's a bit slow... An animated GIF will automatically play when loaded (although if you keep to that size it may still be a bit slow - again you'd need to test it) and if you can reduce the quality a bit you can probably reduce the file size to something more reasonable. Alternatively, combine the images into an AVI and use a simple AVI player to show the animation.

        There are three kinds of people in the world - those who can count and those who can't...

        D Offline
        D Offline
        ddavor
        wrote on last edited by
        #3

        Hi, Thnx for your reply, but I need high quality of graphics with transparency etc. So, GIF and Avi are not solutions. Thnx!

        M S 2 Replies Last reply
        0
        • D ddavor

          Hi, Thnx for your reply, but I need high quality of graphics with transparency etc. So, GIF and Avi are not solutions. Thnx!

          M Offline
          M Offline
          molesworth
          wrote on last edited by
          #4

          Well, GIF images do support transparency, although it's just on/off rather than an alpha value, so you could possibly use that format depending on your use of transparency. GIF also isn't as good for "photo-style" images, where there are a lot of colour gradients, but it works well for images where there are a lot of colour bocks, lines etc. (In fact, for diagrams with lots of colour blocks and sharp edges, it gives much better results.) AVIs can be as high quality as you want as well. You can choose the resolution and whether you want any compression applied. AVIs can have transparency as well, but you'd need to make sure you support that in your player. I wouldn't write of GIF or AVI immediately, as they might, with a little bit of fiddling, be suitable for your needs. If not, I'm not sure what you can do to improve frame rate...

          There are three kinds of people in the world - those who can count and those who can't...

          1 Reply Last reply
          0
          • D ddavor

            Hi, I'm trying to write application where I use series of PNG files for animations. I created control which loads Images from file into ArrayList, and then on specified timer interval I change picture that I want to display. I'm using 1280x720 PNGs. I have 2 problems here: 1) My PNG is around 300KB, and when I execute Image.FromFile("my.png") memory of my process is increased for 4MB. So, if I load 30 pictures, memory will grow to around 130MBs and the problem is that I have to keep lot of images loaded into memory since I'm using it constantly during execution time. 2) performances of DrawImage functions are quite bad and I cannot get proper speed (if I need 25 frames per second for example) Does anyone have some suggestions how to solve this? Thnx in advance!

            H Offline
            H Offline
            Henry Minute
            wrote on last edited by
            #5

            ddavor wrote:

            I execute Image.FromFile("my.png")

            This response is nothing to do with your main problem, but Image.FromFile has been known to cause problems with files becoming locked. The general recommendation is to use Image.FromStream.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            1 Reply Last reply
            0
            • D ddavor

              Hi, Thnx for your reply, but I need high quality of graphics with transparency etc. So, GIF and Avi are not solutions. Thnx!

              S Offline
              S Offline
              Skymir
              wrote on last edited by
              #6

              AVI could do the quality, however the transparency could be a problem. 1280x720 is a LOT of real estate to cover, if the entire area isn't being animated at the same time, you might be better off only redrawing the parts of the screen that change. Or moving a picture around the screen as the animation. Aside from that, your next step would probably be using managed DirectX to pile all those graphics into buffers.

              The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups