Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

377
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda