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 5837985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:25:10+00:00 2026-05-22T11:25:10+00:00

How to display a progressive JPEG as it loads from a web URL? I

  • 0

How to display a progressive JPEG as it loads from a web URL? I am trying to display a Google Maps image in a image control in WPF, but I want to keep the advantage of the image being a progressive JPG.

How to load a progressive JPG in WPF?

Image imgMap;
BitmapImage mapLoader = new BitmapImage();

mapLoader.BeginInit();
mapLoader.UriSource = new Uri(URL);
mapLoader.EndInit();

imgMap.Source = mapLoader;

Currently, I make do with this. It will only shows the image after it loads completely. I want to show it progressively.

  • 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-22T11:25:11+00:00Added an answer on May 22, 2026 at 11:25 am

    A very basic sample. Im sure there are room for optimizations, and you can do a separate class from it that can handle numerous request, but at least its working, and you can shape it for your needs. Also note that this sample creates an image every time that we report a progress, you should avoid it! Do an image about every 5% or so to avoid a big overhead.

    Xaml:

    <Window x:Class="ScrollViewerTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">
      <StackPanel>
        <TextBlock Text="{Binding Path=Progress, StringFormat=Progress: {0}}" />
        <Image Source="{Binding Path=Image}" />
      </StackPanel>
    </Window>
    

    Code-behind:

    public partial class MainWindow : Window, INotifyPropertyChanged
    {
    
      #region Public Properties
    
      private int _progress;
      public int Progress
      {
        get { return _progress; }
        set
        {
          if (_progress != value)
          {
            _progress = value;
    
            if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs("Progress"));
          }
        }
      }
    
      private BitmapImage image;
      public BitmapImage Image
      {
        get { return image; }
        set
        {
          if (image != value)
          {
            image = value;
            if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs("Image"));
          }
        }
      }
    
      #endregion
    
      BackgroundWorker worker = new BackgroundWorker();
    
      public MainWindow()
      {
        InitializeComponent();
    
        worker.DoWork += backgroundWorker1_DoWork;
        worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
        worker.WorkerReportsProgress = true;
        worker.RunWorkerAsync(@"http://Tools.CentralShooters.co.nz/Images/ProgressiveSample1.jpg");
      }
    
      // This function is based on code from
      //   http://devtoolshed.com/content/c-download-file-progress-bar
      private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
      {
        // the URL to download the file from
        string sUrlToReadFileFrom = e.Argument as string;
    
        // first, we need to get the exact size (in bytes) of the file we are downloading
        Uri url = new Uri(sUrlToReadFileFrom);
        System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
        System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
        response.Close();
        // gets the size of the file in bytes
        Int64 iSize = response.ContentLength;
    
        // keeps track of the total bytes downloaded so we can update the progress bar
        Int64 iRunningByteTotal = 0;
    
        // use the webclient object to download the file
        using (System.Net.WebClient client = new System.Net.WebClient())
        {
          // open the file at the remote URL for reading
          using (System.IO.Stream streamRemote = client.OpenRead(new Uri(sUrlToReadFileFrom)))
          {
            using (Stream streamLocal = new MemoryStream((int)iSize))
            {
              // loop the stream and get the file into the byte buffer
              int iByteSize = 0;
              byte[] byteBuffer = new byte[iSize];
              while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
              {
                // write the bytes to the file system at the file path specified
                streamLocal.Write(byteBuffer, 0, iByteSize);
                iRunningByteTotal += iByteSize;
    
                // calculate the progress out of a base "100"
                double dIndex = (double)(iRunningByteTotal);
                double dTotal = (double)byteBuffer.Length;
                double dProgressPercentage = (dIndex / dTotal);
                int iProgressPercentage = (int)(dProgressPercentage * 100);
    
                // update the progress bar, and we pass our MemoryStream, 
                //  so we can use it in the progress changed event handler
                worker.ReportProgress(iProgressPercentage, streamLocal);
              }
    
              // clean up the file stream
              streamLocal.Close();
            }
    
            // close the connection to the remote server
            streamRemote.Close();
          }
        }
      }
    
      void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
      {
        Dispatcher.BeginInvoke(
             System.Windows.Threading.DispatcherPriority.Normal,
             new Action(delegate()
             {
               MemoryStream stream = e.UserState as MemoryStream;
    
               BitmapImage bi = new BitmapImage();
               bi.BeginInit();
               bi.StreamSource = new MemoryStream(stream.ToArray());
               bi.EndInit();
    
               this.Progress = e.ProgressPercentage;
               this.Image = bi;
             }
           ));
      }
    
      public event PropertyChangedEventHandler PropertyChanged;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

'display the left product image if intImagePos = 2 then response.write(<td class=ProductImage> & vbcrlf)
I display set of images(small). I need to show the larger image(300*300) at some
How would one display any add content from a dynamic aspx page? Currently I
I've searched the web and stackoverflow for this. I want to copy multiple files
Display Tag provides pagination feature from the given object. Hibernates provides option to fetch
I display thumbnails in a JPanel. When hovering over such a thumbnail, I want
I display an image in a UIImageView (within a UIScrollView) which is also stored
my question today deals with Flash AS3 video buffering. (Streaming or Progressive) I want
My web applications have pages that display many static fields. I know that poor
I see the value in using progressive enhancement in web development and I already

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.