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
Solved

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

Posted on 2009-06-30
6
395 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and writing to files in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 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