Solved

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

Posted on 2009-06-30
6
396 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

733 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