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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:09:04+00:00 2026-05-15T19:09:04+00:00

I have a data class in my application which maintains a collection of byte

  • 0

I have a data class in my application which maintains a collection of byte arrays representing JPEG images. It’s defined as:

private ArrayList FrameList = new ArrayList();

I’m having some troubles with my Image object rendering a blank page (and taking its sweet time to do it as well). When I insert a blank image with a 2K in-memory byte array (byte x[] = { lots of hex values };):

FrameList.Insert(currFrame, x);

and then import a JPEG file over it later on with:

byte[] bytes = File.ReadAllBytes(fspec);
FrameList[currFrame] = bytes;

the array is read correctly into memory and stored in the ArrayList (confirmed with the debugger).

However,I then have a function to get the image:

public BitmapImage getCurrPicture()
{
    MemoryStream strm;
    BitmapImage bmp = new BitmapImage();
    strm = new MemoryStream((byte[])FrameList[currFrame-1]);
    bmp.CacheOption = BitmapCacheOption.None;
    bmp.BeginInit();
    bmp.StreamSource = strm;
    bmp.EndInit();
    strm.Close();
    return bmp;
}

which is called:

imgPicB.Source = data.getCurrPicture();

and it doesn’t always render.

imgPicB is defined in my XAML as:

<Image x:Name="imgPicB"
       Width="400"
       Height="300"
       Stretch="Fill"
       VerticalAlignment="Top" />

Funny thing is, if I use the exact same JPEG setting the source with setting the source to the file URI directly, it renders fine.

Is there some problem with using in-memory JPEG images in WPF? Is there some extra smarts performed when loading from a file (say auto-detection of the image type)?

  • 1 1 Answer
  • 1 View
  • 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-15T19:09:04+00:00Added an answer on May 15, 2026 at 7:09 pm

    Try this:

    public BitmapSource GetCurrPicture()
    {
        var bitmapImage = new BitmapImage();
        using (Stream stream = new MemoryStream((byte[])FrameList[currFrame-1]))
        {
            bitmapImage.BeginInit();
            bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapImage.StreamSource = stream;
            bitmapImage.EndInit();
            bitmapImage.Freeze();
            return bitmapImage;
        }
    }
    

    This works by having WPF decode the image immediately with OnLoad, and then release the reference to the stream when it is done. This means the stream can be garbage collected when it leaves the function. Otherwise, BitmapImage could hold onto the stream until it is rendered.

    In the code posted in the question, the render would fail because:

    • the decode is delayed; and
    • the stream has been closed at the point where the decode tries to happen.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code first application which defined like this: public abstract class Entity
In my Android application I have an Observable Data class, which contains a method
I have a Core Data class Meeting with a property date which I want
I have an application which requires data to be fetched from a received message
I have a application which needs to poll data at frequent intervals. I had
I have an application which uses JTables to display data, and the cells are
I have an android application which in its main activity, data are adapted from
I have an application which consists of two activities/screens and a java class from
I have an application which upon start request around 10-12KB of data from server
I would like to have an application which either loads or saves data through

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.