tags:

views:

1395

answers:

7

Hi,

I'm currently working on an app that allows the user to play (automatically scroll) through a series of local images. Usually there will be five or six on screen at once.

The major bottleneck at the moment seems to be the actual loading of the image data from disk. A timer thread calls for the images to be updated every 1/6 of a second and the app is struggling to keep up with that speed. Each image is around 25Kb.

I tried creating a rolling cache to try and preload images but this was also getting caught up with itself so ended up slowing down just as much.

Every beat of the timer, I'm looping through the six image placeholders loading the next image using the standard

Image img = Image.FromFile("filename");

method but thought someone might know of a faster way to get the images off disk.

There are between 500 and 20,000 images in each of the six sets so it's too large to load the whole thing into memory at the start.

If anyone has suggestions for a faster way to pull these images through, it would be greatly appreciated.

Thanks,

Kev


Edit to add some more detail of application flow.

Okay, this is what's happening:

User hits 'play' button. Timer thread starts with 1/6 second timeout.

Timer callback:

Update image index (_index++)
for each viewer in list of visible viewers (the forms to display images)
{
    get the filename from the id stored in the viewer
    check to see if the file exists
    if it does exist,
        create new bitmap from image
        and return that image
    otherwise return null

    if returned image isn't null, display it on screen
}

That's obviously going across a few layers - the image loading goes on in the services layer and then passes this through to presentation and then to the UI but that's the gist of what's happening.

A: 

Easiest might be to put a 'next' and 'previous' button to limit the number of images and preload.

Gert
A: 

If you have 6 images displayed at once, and you change them all every 1/6 of a second, you should be running into performance issues. Loading 150 kb from disk should be a trivial activity even without caching. It sounds like you may be overdoing the file loads. Are you sure you are only loading 6 images at a time? Are you reading images from disk that are not displayed?

If you can you provide a little more detail of the application flow, I may be able to be a little more helpful.

Neil
Hi, I've edited the question to show a bit of the app flow. It's definitely only loading the 6 images at once. If I start closing down some of the 'viewer' windows, it's noticeably speeding up.I had also tried reading the first 50 images from each set into memory before playing and that totally eliminates the bottleneck, so it seems to be just the loading that slows things down.
Kevin Wilson
+6  A: 
Bernhof
I wrote a quick test app to test this, and the ImageFast is faster by 11 million ticks. The from file of the Image takes 19 million while the ImageFast only takes 7 million.
David Basarab
Thanks for the test results, David :)
Bernhof
Not a problem. I like the ImageFast results.
David Basarab
Many thanks, I've updated the loading mechanism to use this to read from disk. I'll probably use this along with the double buffering and see how fast I can get it running.
Kevin Wilson
A: 

i would probably create a background thread to continously fetch all the images from disk (keeps the ui responsive) and then publish each newly loaded image via an event

Johannes Rudolph
+1  A: 

Check out the concept of double buffering. What you want to be doing is have a second thread that can be loading the next set of images while you are displaying the first set. Once the 1/6 time gate hits, you switch the one set of images out and start loading the next set.

Joel Martinez
A: 

1) browse an image(gif/jpeg) from disk using c#,asp.net????......and how to store image in sql server?and how to read stored images from sql server in gridview........??? 2) How to make selected text in textbox(multiple)(bold,italic,underline...) using c#,asp.net?and how to store formatted textin sqlserver?

waiting for reply.................

sreeranjini
You should better ask this as a new question (or several questions), more people would look at it and try to help you. (And it's not an answer to this question, so not very helpful here in that respect.)Try to make it as clear as possible what you are doing and where the problems ae.
sth
A: 

Hello,

I think concept of double buffering will be useful. Set "Double Buffer" property of the form to True. This will help you little bit. Following links may be useful to you

Virat Kothari