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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:00:52+00:00 2026-05-20T16:00:52+00:00

Hi i have been looking for a solution to display images in image control

  • 0

Hi i have been looking for a solution to display images in image control that is inside the list box.I have seen to set image source and assigning it new BitmapImage(new Uri(stringX)).

Not in my case i first retrieve all the images from URL using WebClient that is in function and that function returns MemoryStream after some process.

Now what i want to do is display that image so i don’t have Uri to create new bitmap.So i tried to Implement StreamSource but i get

  Set property 'System.Windows.Media.Imaging.BitmapImage.StreamSource' threw an exception.

here goes my code

Retrieve Image From Web

public MemoryStream GetImage(string id)
        {
            WebResponse result = null;
            Image rImage = null;
            MemoryStream imageStream = null;
            try
            {
                string url = "https://devnmark.com/" + id + "/picture";
                WebRequest request = WebRequest.Create(url);
                result = request.GetResponse();
                Stream stream = result.GetResponseStream();
                BinaryReader br = new BinaryReader(stream);
                byte[] rBytes = br.ReadBytes(1000000);
                br.Close();
                result.Close();
                imageStream = new MemoryStream(rBytes, 0, rBytes.Length);
                imageStream.Write(rBytes, 0, rBytes.Length);
                rImage = Image.FromStream(imageStream, true);
               // imageStream.Close();
            }
            catch (Exception c)
            {
                //MessageBox.Show(c.Message);
            }
            finally
            {
                if (result != null) result.Close();
            }
            return imageStream;

        }

Class Declared for Type

 class UserInfo
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool IsChecked { get; set; }
        public MemoryStream Picture { get; set; }
    }

Load Images

 private void LoadFriends()
        {
            foreach (dynamic imge in MainList)
            {
                if (x >= 6)
                    break;
                UserInfo info = new UserInfo();
                info.Id = int.Parse(imge.id);
                info.Name = imge.name;         
                info.Picture = function.GetImage(info.Id.ToString());
                FriendList.Add(info);
                x++;
            }
            list.ItemsSource = FriendList;
        }

XMAL for ListBox

<ListBox x:Name="list"  Margin="18,100,535,74" >
    <ListBox.ItemTemplate>
       <HierarchicalDataTemplate>
          <StackPanel Orientation="Horizontal">
             <Image Height="50" Width="50">
                 <Image.Source>                                    
                   <BitmapImage StreamSource="Picture" ></BitmapImage>
                 </Image.Source>
             </Image>
             <my:RibbonCheckBox Label="{Binding Name}" IsChecked="{Binding IsChecked}" />                    
          </StackPanel>                     
      </HierarchicalDataTemplate>      
    </ListBox.ItemTemplate>                 
</ListBox>
  • 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-20T16:00:52+00:00Added an answer on May 20, 2026 at 4:00 pm

    You have a big bunch of problems.

    byte[] rBytes = br.ReadBytes(1000000);
    

    What if the image is larger than 1MB?

    Remove the line

    rImage = Image.FromStream(imageStream, true);
    

    You don’t use the result from that, it just will take processing time and position the imageStream at the end.

    You should probably use MemoryStream.Seek() to reset the stream to it starting position before returning.

    imageStream.Seek(0, SeekOrigin.Begin);
    

    Edit

    Your XAML binding is wrong

    <BitmapImage StreamSource="Picture" ></BitmapImage>
    

    Should be

    <BitmapImage StreamSource="{Binding Picture}" ></BitmapImage>
    

    to be a valid binding, but I’m actually not sure if you can bind StreamSource at all or if you need to initialize from code, like in the example at the very bottom of the msdn doc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking into Adjacency List and Nested Set Model to find the
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been looking at jQUery thickbox for showing modal dialogs with images, it
I have been looking all day for a PHP or JavaScript solution to do
I have been looking for a solution to this issue for a few days
I have a problem with this code. I have been looking for the solution
I have been looking around for hours trying to find a clear simple solution
I have been looking for a solution to this for a while though and
I have been looking into IKVMing Apache's FOP project to use with our .NET
We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance

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.