开发者

Show images from folder by scrolling in scrollbar is laggy?

I have 1 picturebox and 1 "VScrollbar" ( vertical scrollbar ). When i change the value of the scrollbar i want 开发者_StackOverflow中文版to get a picture from my folder in disk and show the image in the picturebox. I only want to show 1 picture a time.

It works but it is "laggy" because everytime i scroll, i get the index of the scroll, get the file from my folder ( depending on the index of the scroll ) and then making a bitmap and binding it to the picturebox.

private void ScreenBarScroller_ValueChanged(object sender, EventArgs e)
{
    int scrollValue = 
        ScreenBarScroller.Value == 0 ? 0 : ScreenBarScroller.Value - 1;

    ScreenClass currentScreen = ScreenList[scrollValue];

    using (Bitmap newPicture = new Bitmap(
                               new FileStream(currentScreen.Path,
                               FileMode.Open, FileAccess.ReadWrite, 
                           FileShare.Delete | FileShare.ReadWrite)))
    {
            pictureBox1.Image = 
               ResizeBitmap(newPicture, pictureBox1.Width, pictureBox1.Height);
    }
}

The code works but its so damn laggy , i want the "smooth" scrolling . How can i do that? Is there a better way to do this then VScrollbar?


One of possible solutions can be load also images in the range of, let's say, next 5 images in background thread. So at the moment user goes to the next image it's already loaded or at least in loading.

Another solution can be use memory mapping on your bitmaps which will invrease performanse of reading from disk.

Can also merge these 2 solutions.

EDIT

Important is, by me, if these are big enough images, to load them in another thread and notify to the user via message on UI that image is in loading, so you will give sence of responsivness to your app. There is nothing worse for UX to leave user without a clue what is going on now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜