Solved

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

Posted on 2009-06-30
6
387 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Accepted Solution

by:
jgordos earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks guys. Ive not had time to try it out but Im sure this will work
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
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.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now