Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

373
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!