Results 1 to 17 of 17

Thread: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

  1. #1

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Resolved [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    Chaps,

    I have an explorer-like control that reads PNGs from file, placing the images in a standard picBox grid. It works. It reads and displays 12 of these images at a time. On newer systems with SSDs and powerful CPUs there is very little delay in refreshing all 12 picBoxes. In the past I ran this on a 2.0ghz Core@Duo on a 5400rpm HD and the delay was noticeable though not terrible. Regardless I'd like to tune the experience for the user and speed up each subsequent scroll down/up that the user makes.



    At the moment, when the user scrolls down the grid is cleared and re-read from file. Each picturebox is re-read from PNG source until the grid is full. Any image that was in the picBoxes beforehand is discarded.

    My aim would be to read any old images from the picbox prior to discarding them down and instead insert them into an imageList to display those when the user finds an image that is already in the cache.

    I am wondering if this effort is worthwhile considering there will be an overhead of writing to/reading from the imageList in comparison to reading straight from the PNG.

    The original images are quite big PNGs at 256x256 so reading and parsing the data takes some CPU and i/o but when the grid is populated I resize them down to 64x64 or 32x32 depending upon the view so there might be some benefit in just reading small images from an imagelist.

    Also, would it be quicker to use another construct such as a dictionary or is an imageList sufficiently quick? I am familiar with dictionaries and have used them to cache my dock in the past but found dictionaries can be unwieldy when resizing. Would it sensible to simply cache as smaller versions of the file?

    Your thoughts please...
    Last edited by yereverluvinuncleber; May 31st, 2022 at 08:03 AM. Reason: Added image
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: VB6 QUESTION: Best Method for caching Small Images

    You've posted this in the CodeBank forum, so not for questions. I've asked the mods to move this thread.

  3. #3

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: VB6 QUESTION: Best Method for caching Small Images

    Quote Originally Posted by jmcilhinney View Post
    You've posted this in the CodeBank forum, so not for questions. I've asked the mods to move this thread.
    Oops, not sure how that happened, sometimes the forum displays slowly due to my slow internet connection and my click on the right portion of the forum may have gone astray. Those adverts at the top often displace the main forum whilst their images display. My apologies.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: VB6 QUESTION: Best Method for caching Small Images

    Quote Originally Posted by yereverluvinuncleber View Post
    Oops, not sure how that happened, sometimes the forum displays slowly due to my slow internet connection and my click on the right portion of the forum may have gone astray. Those adverts at the top often displace the main forum whilst their images display. My apologies.
    Happens to me all the time. I keep ending up on the home page instead of the New Posts page. I don't have a particularly slow connection, but the ads seem to take a while to pop in and then they arrive at the worst possible moment.

  5. #5

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: VB6 QUESTION: Best Method for caching Small Images

    No responses, so I am assuming I am on the right lines.

    Let me distill the question. Cacheing resized images, should I use?:

    1. ImageList
    2. Dictionary
    3. From file
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  6. #6
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: VB6 QUESTION: Best Method for caching Small Images

    optimization should be:
    - read all png and store those in a memoryDC that u can later reuse when needed. remember we have quite a lot of memory nowadays.
    - use gdialphablend to render.

  7. #7

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: VB6 QUESTION: Best Method for caching Small Images

    OK, I hear what you are saying but I am trying to use off-the-shelf solutions that a typical VB6er might use, using standard controls to optimise image loading. Basically, I want to finish this application and not introduce too many levels of complexity that will give me more to do than I want.

    Really, I want to teach myself about imageLists and their potential uses. What I am trying to determine is whether using an imageList is a significantly worse choice than a dictionary.

    Once this is done and achieved. I will consider the next step and what I need to learn to implement that.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: VB6 QUESTION: Best Method for caching Small Images

    What about keeping it in array?
    Sample below is for a single Picture, but......
    Code:
    Option Explicit
    
    Dim nPic As New StdPicture, iPic As IPicture
    
    Private Sub Form_Load()
      Set nPic = Picture1.Picture
      Set iPic = nPic
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
      Set nPic = Nothing
      Set iPic = Nothing
    End Sub
    
    Private Sub Command1_Click()
      Picture1.Picture = LoadPicture("")
    End Sub
    
    Private Sub Command2_Click()
      Set Picture1 = iPic
    End Sub
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  9. #9

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: VB6 QUESTION: Best Method for caching Small Images

    I assume that arrays are quicker than lists... I will experiment.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  10. #10

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    In the end I added an imageList and for each image read from file and displayed, I added it to the imageList in its resized form.

    Each image was given a unique name as a key relating to its position in the grid. This key's existence is checked just before any image is accessed, if the key exists then the resized .picture is extracted from the imageList rather than reading it from file.

    Each subsequent access is much, much faster as we are retrieving from memory and only retrieving a tiny image rather than the big 256x256 one on disc.

    I could attempt an array of images and see if that is faster than an imageList (I am sure it will be) but having each image stored under a unique key is a very useful feature and the imageList cache is also as fast as I need it to be. Thanks for your help.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  11. #11
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    glad it worked for u. yeah caching is the way to go.
    theres picture browser tools that have this "pre-loading" functions. so they would load ahead of time to make it faster "if" you decide to view that picture.
    doing so for you, would also make it a bit faster. of course u need a good recursive function that would not create any lagging while it operates in the background, of course when idle
    (idle=is when you are not doing anything at all. I usually have a release-time of 1 second before the operations starts again after the user did his last command)

    to make everything even faster, is the suggestion I wrote, load into memoryDC (array) and with a "key/filename", that u can access very fast.
    GDI32 has gdialphablend that is superfast as well.

  12. #12

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    Yes, in the absence of multi-threading, I considered pre-loading using a timer that came into operation only when the user was idle for a period of time and continuously checking a flag for any user interaction. Then I could pre-load un-cached images whilst the app is idle. I may still do that.

    The creation of this app. is all about teaching me how things are done and I imagine my explorer-type pane is emulating some of the operations that are done in a proper file manager app..
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    Why not just use ListView with ImageList controls?

    How many images are involved? Is it a fixed list, or the contents of a directory chosen by the user?

    Why is a cache needed at all? Is the goal to make scrollback (images previously retrieved) faster than scrollforward (more images)?

    What about when the user presses Ctrl-End to speed to the last item? Wouldn't you need to retrieve every image in the entire list anyway?

  14. #14
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    To me, this is another example of inadequate specifications. First and foremost, I'd want to know if we're after image display speed, memory compactness, or some balance of the two. The answer to that question would absolutely affect my approach to doing this.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  15. #15
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,721

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    programming is about learning, trial-and-error and not always go directly into the best solution. yereverluvinuncleber already explained that in a previous post and its a good move to learn.

  16. #16
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    Well one issue with the two OCXs we have for ImageList controls is that we can't specify the color depth as 32bpp. That keeps us from using alpha transparency even though the version 6 comctl32.dll we can use via the older comctl32.ocx is capable of storing and rendering them.

    That's probably only a problem for the version 6 comctl32.ocx ListView when you have the Explorer theme set on it via SetWindowTheme(). In that case hotlighted and selected items often show a white or other-colored "fringe" because the alpha channel was lost.

  17. #17

    Thread Starter
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: [RESOLVED] VB6 QUESTION: Best Method for caching Small Images

    Well, I am quite content with the post-fetch cache-ing improvements using just an imageList for a start, though I may experiment more later with other methods. In other tools I have 'cached' images using a dictionary prior to use and created an intermediate resized-file location to speed up startup times. I can always optimise further and learn as I go.

    In this particular tool I am currently thinking how to cause the remaining images in a folder to be partially pre-fetched using some sort of background task when idle. We'll see how this goes.

    There is no 'specification' for this utility as it has outgrown its initial spec. and is now a growing project used almost entirely as a teaching aid. As I find some functionality done rather well elsewhere, I try to understand and emulate it, even if only partially. It teaches me more VB and that feels good.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width