Solved

How Do I Display An Image stored as an Array of Longs in a Windows Form

Posted on 2009-06-30
6
391 Views
Last Modified: 2013-12-26
Hello All

Im using Visual Studio 2008 and programming in C/C++

Ive an array of longs  (obtained from a digital camera) that represent an image.
Lets call the array 'imgArray'
The array is big at 1002 * 1004

My question is simple. How do I display this image in a windows form?
Note I dont want to save it to the hard drive then load it again. I just want to display the pixel information stored in 'imgArray' directly into a windows form.  
Can someone explain how I do this? Thanks.
0
Comment
Question by:rangers99
  • 3
  • 2
6 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24744072
There are many ways of internally representing image data. Apparently this is yet another one. Without in-depth knowledge about what each long stands for, it will be quite hard to transform it into a BMP format, which could consequently be used to display the image.

Can you explain what the format is that your longs are using? How should the header information be interpreted (width, length, color depth, encoding, camera info etc)? Do you have a struct of some sort that represents your array?
0
 

Author Comment

by:rangers99
ID: 24744530
abel
Each array entry represents the pixel colour. There is no header information. Its just a straightforward array of raw data.
0
 
LVL 39

Expert Comment

by:abel
ID: 24744699
The size of a long is dependent on the architecture. It is 4 bytes or 8 bytes? If it is 4 bytes, what is the order of the pixels? Nothing - Red - Green - Blue? or Alpha - Red - Green - Blue? or Cyan - Magenta - Yellow - Black? There are other schemes even.

If it is 8 bytes, how to extract the color info?

How do you determine the width/height or is it always fixed to the dimensions 1002 x 1004?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 11

Accepted Solution

by:
jgordos earned 100 total points
ID: 24745180
I think in this particular case, I'd just pull the rope on it, and see what happens....

Basically, create the form ... Add a pictureBox (System.Windows.Forms.PictureBox) I called it "output", so when you see "output", that's the pictureBox.

I then created a class, and inside the class I have declared
Bitmap myReconstructedBitmap = new Bitmap( 1002, 1004 );

for( int y = 0; y < myReconstructedBitmap.Height; y++ )
{
for ( int x = 0; x < myReconstructedBitmap.Width; x++ )
{
Color theColor;
/* This part is a guess.  You'll need to play with these values here.. */
long pixelData = imgArray[y][x];
char red = pixelData >> 24;
char green = pixelData >> 8;
char blue = pixelData >> 16;
theColor = Color.FromArgb( red, green, blue );
myReconstructedBitmap.SetPixel( x, y, theColor );
}
}

Later, I set the pictureBox.image to the reconstructed bitmap...

this.output.Image = myReconstructedBitmap;



I have no idea if this will actually WORK; the data in your array may or may not really look the way I'm guessing it is...

But, you should be able to eyeball it and see something that will help you identify the proper format of the data in your image buffer.

Hope this helps,

-john


0
 
LVL 39

Assisted Solution

by:abel
abel earned 25 total points
ID: 24745261
was just about to suggest using a BITMAPINFO and to emphasize on the order of bytes in the RGBQUAD structure (not being RGB but BGR). If it maps correctly to your long, you can use memmove. Otherwise, you'd need such a thing as john's loop (which is the same, but shows how to translate the colors)

-- Abel --
0
 

Author Closing Comment

by:rangers99
ID: 31598290
Thanks guys. Ive not had time to try it out but Im sure this will work
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question