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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:15:36+00:00 2026-05-16T00:15:36+00:00

I start out with a 128 x 128 array of doubles and turn that

  • 0

I start out with a 128 x 128 array of doubles and turn that into a 1D array of bytes with proportional values for each double.

I then take this array of bytes and turn it into a memory stream (dataStream below) and try and put that into a BitmapImage like so:

imgScan.Width = 128;
imgScan.Height = 128;
BitmapImage bi = new BitmapImage();
bi.SourceRect = new Int32Rect(0, 0, width, height);
bi.StreamSource = dataStream;
imgScan.Source = bi;

Here imgScan is a System.Windows.Controls.Image

This doesn’t produce the expected image (I just get a white square).

How should I be going about this?

  • 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-16T00:15:37+00:00Added an answer on May 16, 2026 at 12:15 am

    I think you’ll find that in your code, the stream should contain a complete image file, not a raw block of data. Here’s making a Bitmap from a block of data (it’s not greyscale, but you might get the idea):

    const int bytesPerPixel = 4;
    int stride = bytesPerPixel * pixelsPerLine;
    UInt32[] pixelBytes = new uint[lineCount * pixelsPerLine];
    
    for (int y = 0; y < lineCount; y++)
    {
        int destinationLineStart = y * pixelsPerLine;
        int sourceLineStart = y * pixelsPerLine;
        for (int x = 0; x < pixelsPerLine; x++)
        {
            pixelBytes[x] = _rgbPixels[x].Pbgr32;
        }
    }
    var bmp = BitmapSource.Create(pixelsPerLine, lineCount, 96, 96, PixelFormats.Pbgra32, null, pixelBytes, stride);
    bmp.Freeze();
    return bmp;
    

    You’ve already done the bit in the nested loops (making the byte array), but I left it in so you can see what comes before the Create

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

Sidebar

Related Questions

I start out with an array of strings where each element of the array
I'll start out by giving you the code I'm working on so that you
Let me start out by saying that I'm not a C developer and I
I'm working on early designs for an application that needs to start out small
Need some help assigning a mouseover event to display some icons that start out
I should start out by saying that I am fairly new to Java EE
Let me start out by saying that I'm not a JavaScript developer so this
To start out with, I basically have a function that opens up a text
Lets start out with an simple 16 x 16 array of ints. How would
So I would like to start out by telling you that I am learning

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.