?
Solved

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

Posted on 2009-06-30
6
Medium Priority
?
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 11

Accepted Solution

by:
jgordos earned 400 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 100 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

Industry Leaders: 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!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

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