Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

380
Vistas
C# how can I extract photos from a zip file faster and more efficiently without extracting them using ZipArchive

I have a xamarin app that reads photos without extracting them into a zip file.

When I click very quickly on the page where the photos should be displayed. Sometimes half doesn't show because the app hasn't been able to read them all yet.

Navigating after that page goes like this

    public async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
    {
        Content tappedStep = (Content)MyListView.SelectedItem;
        int stepIndex = tappedStep.contentid;
        string nextTitle = _protocol.name;
        using (UserDialogs.Instance.Loading("Loading", null, null, true, MaskType.Black))
        {
            loading = true;
            if (loading)
            {
                Title = nextTitle;
            }
            await Navigation.PushAsync(new StepView(_protocol, Title, tappedStep.chaptertitle, stepIndex));
        }

        ((ListView)sender).SelectedItem = null;
    }

So if I want to navigate too quickly after the stepview, the photos are often not all there.

This is the code I use to read the photos in the zip file.

    private string PathToZip()
    {
        string folderName = $"protocol-{_protocol.id}-{_protocol.versionnr}.zip";
        string extractPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
        string zipPath = $"{$"{extractPath}"}/{$"{folderName}"}";
        return zipPath;
    }

    private async Task GetImage()
    {
        try
        {
            PathToZip();
            int currentIndex = GetCurrentIndex();
            Content content = _protocol.contents[currentIndex];
            string imageName = $"{content.contentid}.jpg";
            using (ZipArchive archive = ZipFile.OpenRead(PathToZip()))
            {
                for (int i = 0; i < archive.Entries.Count; i++)
                {
                    ZipArchiveEntry pictureEntry = archive.Entries[i];
                    if (pictureEntry.Name == imageName)
                    {
                        //for reading the image
                        byte[] buffer;
                        long length = pictureEntry.Length;
                        buffer = new byte[length];
                        pictureEntry.Open().Read(buffer, 0, (int)length);
                        myImage.Source = ImageSource.FromStream(() => new MemoryStream(buffer));
                        
                    }
                }
            }
        }
        catch (Exception)
        {
        }
    }

How can I make this more efficient so that if the app hasn't loaded everything yet, when I want to navigate to the next page, the app then waits for each page to be read?

Thanks in advance

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda