Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3855426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:46:28+00:00 2026-05-19T17:46:28+00:00

I’m in need to load an bunch of bitmaps in my application. The problem

  • 0

I’m in need to load an bunch of bitmaps in my application. The problem is that the loading make the form very slow. My actual class is as follows:

public class ImagensDisponiveis
{
    /// <summary>
    /// List of  ImagemSygic struct
    /// </summary>
    private List<ImagemSygic> _poolImagens;
    /// <summary>
    /// index of next avaiable image
    /// </summary>
    private int indiceProximoDisponivel;
    /// <summary>
    /// Path to image folder
    /// </summary>
    private string caminhoPasta;
    /// <summary>
    /// Number of found images that conforms to patterm
    /// </summary>
    private int MAXCOUNT;


    public ImagensDisponiveis(string caminhoPastaRecursos)
    {
        indiceProximoDisponivel = 0;
        caminhoPasta = caminhoPastaRecursos;

        PreencherPool(out _poolImagens, caminhoPasta);
        MAXCOUNT = _poolImagens.Count;
    }

    /// <summary>
    /// Preenche a lista de imagens com uma estrutura que contém a imagem e o caminho dessa imagem para o Sygic
    /// </summary>
    /// <param name="_poolImagens">The _pool imagens.</param>
    /// <param name="filepath">The filepath.</param>
    private void PreencherPool(out List<ImagemSygic> _poolImagens, string filepath)
    {
        DateTime momentoInicio = DateTime.Now;
        _poolImagens = new List<ImagemSygic>();
        string[] imagens = Directory.GetFiles(filepath);
#if DEBUG
        //int counter = 0;
        //int numFiles = imagens.Length;
#endif
        foreach (string caminhoImagem in imagens)
        {

            try
            {
                string filename = Path.GetFileName(caminhoImagem);
                //original image to show on .net [POI]anything.bmp
                //image that sygic tries to use on drive ?[POI]anything.bmp, where ? is an number between 1 to 6
                bool valido = filename.StartsWith("[POI]", StringComparison.InvariantCulture);
                //Log.writeToLog(caminhoImagem + " " + valido.ToString());
                if (valido)
                {

                    var streamImagem = File.Open(caminhoImagem, FileMode.Open, FileAccess.Read);
                    Bitmap temImagem = new Bitmap(streamImagem);
                    ImagemSygic tempImgSygic = new ImagemSygic();
                    tempImgSygic.CaminhoImagemSygic = caminhoImagem;
                    tempImgSygic.ImagemWindows = temImagem;
                    tempImgSygic.SygicImageID = -1;
                    _poolImagens.Add(tempImgSygic);
#if DEBUG
                    //counter++;

#endif
                }
            }
            catch (ArgumentException aec)
            {
                Log.writeToLog("[EXCEPCAO ImagensDisp]: ArgumentException - " + aec.Message);
            }
            catch (UnauthorizedAccessException uae)
            {
                Log.writeToLog("[EXCEPCAO ImagensDisp]: UnauthorizedAccessException - " + uae.Message);
            }

            catch (Exception exc)
            {
                Log.writeToLog("[EXCEPCAO ImagensDisp]: Exception - " + exc.Message);
            }
        }

        DateTime tempoFim = DateTime.Now;

        TimeSpan duracao = tempoFim.Subtract(momentoInicio);
        Log.writeToLog("[Criacao da pool] Demorou " + duracao.TotalSeconds.ToString());
    }
    /// <summary>
    /// OObtains the next avaianle ImagemSygic if there is an avaiable
    /// </summary>
    /// <returns>ImagemSygic if possible, else null</returns>
    public ImagemSygic ObterProximoDisponivel()
    {
        if (indiceProximoDisponivel > MAXCOUNT)
            return null;
        else
        {
            ImagemSygic imagemRetornar = _poolImagens[indiceProximoDisponivel];
            indiceProximoDisponivel++;
            return imagemRetornar;
        }
    }

    public void ResetCounter()
    {
        indiceProximoDisponivel = 0;
    }


}

/// <summary>
/// Class that contains the Bitmap preview and the original path to that image
/// </summary>
public class ImagemSygic
{

    private volatile int _imageID;
    /// <summary>
    /// Gets or sets the imagem windows.
    /// </summary>
    /// <value>The imagem windows.</value>
    public Bitmap ImagemWindows { get; set; }
    /// <summary>
    /// Gets or sets the caminho imagem sygic.
    /// </summary>
    /// <value>The caminho imagem sygic.</value>
    public string CaminhoImagemSygic { get; set; }

    /// <summary>
    /// Gets or sets the sygic image ID.
    /// </summary>
    /// <value>The sygic image ID.</value>
    public int SygicImageID
    {
        get
        {
            return this._imageID;
        }
        set
        {
            this._imageID = value;
        }
    }
}

/// <summary>
/// 
/// </summary>
public class POISygic
{

    private volatile int _latitude;
    private volatile int _longitude;
    /// <summary>
    /// Gets or sets the imagem.
    /// </summary>
    /// <value>The imagem.</value>
    public ImagemSygic Imagem { get; set; }
    /// <summary>
    /// Gets or sets the latitude.
    /// </summary>
    /// <value>The latitude.</value>
    public int Latitude { get { return this._latitude; } set { this._latitude = value; } }
    /// <summary>
    /// Gets or sets the longitude.
    /// </summary>
    /// <value>The longitude.</value>
    public int Longitude { get { return this._longitude; } set { this._longitude = value; } }
    /// <summary>
    /// Gets or sets the descricao.
    /// </summary>
    /// <value>The descricao.</value>
    public string Descricao { get; set; }

    /// <summary>
    /// Gets or sets a value indicating whether this instance is displayed now.
    /// </summary>
    /// <value>
    ///     <c>true</c> if this instance is displayed now; otherwise, <c>false</c>.
    /// </value>
    public bool isDisplayedNow { get; set; }

    /// <summary>
    /// Gets or sets the elem ID.
    /// </summary>
    /// <value>The elem ID.</value>
    public int elemID { get; set; }


}

The objective of this class is to read an serie of bitmaps that have the [POI] prefix to allow .net to display an legend in an form control to the poi image appearing in an Sygic Drive window.

The question is how i can optimize this code to load the images faster. At the moment it loads 26 315k bitmaps images in 10s. But probably in the final solution we could have as many as +260 images, so that is the reason of the need of optimization.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:46:29+00:00Added an answer on May 19, 2026 at 5:46 pm

    The biggest potential improvement I see is that PreencherPool loads all images in a folder. Are you showing all images at once? If not, you could change that to lazy-load the images on demand, or at least load them in a background thread so the caller doesn’t block while they all get loaded.

    I’d also suggest that 300k seems a bit large for a “thumbnail” (which the code suggests they are). Are you sizing it to what you actually need for displ15?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.