Problems with using series of PNG files as animations
-
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!
-
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!
Firstly, PNGs aren't really the best way to do animations. You should maybe think about using GIF images instead.
ddavor wrote:
- 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:
- 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...
-
Firstly, PNGs aren't really the best way to do animations. You should maybe think about using GIF images instead.
ddavor wrote:
- 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:
- 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...
-
Hi, Thnx for your reply, but I need high quality of graphics with transparency etc. So, GIF and Avi are not solutions. Thnx!
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...
-
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!
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 useImage.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.”
-
Hi, Thnx for your reply, but I need high quality of graphics with transparency etc. So, GIF and Avi are not solutions. Thnx!
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.