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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:16:01+00:00 2026-06-01T07:16:01+00:00

I have been tackling this problem for some time. I get the image from

  • 0

I have been tackling this problem for some time. I get the image from my DB as a byte[] and i want to convert it to WritableBitmap so i can use binding to show it on my xaml page.

I am using this:

 public class ImageConverter : IValueConverter
{
    /// <summary>
    /// Converts a Jpeg byte array into a WriteableBitmap
    /// </summary>
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is byte[])
        {
            MemoryStream stream = new MemoryStream((Byte[])value);
            WriteableBitmap bmp = new WriteableBitmap(200, 200);
            bmp.LoadJpeg(stream);
            return bmp;
        }
        else
            return null;
    }
    /// <summary>
    /// Converts a WriteableBitmap into a Jpeg byte array.
    /// </summary>
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

The first problem is that it doesn’t work. it throws an unspecified exception when it hits bmp.LoadJpeg(stream);

The second problem is regarding the fixed size passed to the WriteableBitmap constructor, how can i know the size of the photo that is coming from the db ? can i make it dynamic somehow ? I guess the second problem is the cause of the first one.

Thanks.

EDIT

I have also tries using PictureDecoder.DecodeJpeg() like this:

            MemoryStream stream = new MemoryStream((Byte[])value);
            WriteableBitmap bmp = PictureDecoder.DecodeJpeg(stream);
            return bmp;

but it didn’t work either. in this case PictureDecoder.DecodeJpeg suppose to create the bmp object for me. I still get an unspecified error. could it be that i passed the maximum length allowed for the stream ?

  • 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-06-01T07:16:03+00:00Added an answer on June 1, 2026 at 7:16 am

    Thanks for your answer

    It seems that the problem was that the stream coming from the db was corrupted somehow. the value converter was actually okay. i have changed it to use PictureDecoder.DecodeJpeg() instead so it will be more clean and dynamic

    public class ImageConverter : IValueConverter
    {
    /// <summary>
    /// Converts a Jpeg byte array into a WriteableBitmap
    /// </summary>
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is byte[])
        {
            MemoryStream stream = new MemoryStream((Byte[])value);
            WriteableBitmap bmp = PictureDecoder.DecodeJpeg(stream);
            return bmp;
        }
        else
            return null;
    }
    /// <summary>
    /// Converts a WriteableBitmap into a Jpeg byte array.
    /// </summary>
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hoping I can get some architectural advice on this. I have been given the
Have been trying to fix this problem I have here. Basically I have a
Have been working on a Tower Defense game for iOS for some time now.
Have been looking at the MVC storefront and see that IQueryable is returned from
Have been getting pretty bald over this situation! I am using MS VS 2010
Have been reading around on IErrorHandler and want to go the config route. so,
Sorry if this has been asked elsewhere, I've been looking and can't find it
have been working and wearing out my fingers doing google searches with this one:
The following problem has been puzzling me for a couple of days (nb: this
Have been trying to get integration testing working with my seam project and the

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.