.NET Framework Class Library | PictureBox class | how to display an image which is in memory

.NET Framework Class Library | PictureBox class | how to display an image which is in memory

Post by Johan "MrD » Wed, 27 Apr 2005 03:59:54

I've got an unsigned char pointer to a 1d array of rgb data, i know its
size (which is the same for x and y). I want to display this image
inside a PictureBox in my Form if the user presses a button.

I do not know how to achieve this, i browsed the mdsn docs for quite a
while but so far i'm only able to display images from disk/ressources.

Is there some function able to set the data? Could anyone point me to
the right direction?

btw: I'm using msvc .net 2003, the project type is "windows forms
application", running on windows xp professional

thanks, Johan.

 
 
 

.NET Framework Class Library | PictureBox class | how to display an image which is in memory

Post by Johan "MrD » Wed, 27 Apr 2005 04:15:32

> btw: I'm using msvc .net 2003, the project type is "windows forms

I forgot to mention the language used is c++.

 
 
 

.NET Framework Class Library | PictureBox class | how to display an image which is in memory

Post by Johan "MrD » Wed, 27 Apr 2005 05:56:09

> There is no dynamic data binding on a Picture Box Control that I know of.

Thanks for your reply. Anyways this will not help. In my post i've
simplified the problem to make my question a bit shorter.

What i really want to do however is generate procedural textures using
user controllable parameters which i pass to my allready written
procedural texture class functions.

Every time the user is done setting his parameters he'll click on
"update" and the new image should appear in the picture box. So it will
be kind of interactive and any file based picture reading couldn't do that.

If the picture box can't do it what else could i try?

Johan.
 
 
 

.NET Framework Class Library | PictureBox class | how to display an image which is in memory

Post by Johan "MrD » Wed, 27 Apr 2005 06:29:46

Nevermind i've found a way to do it with a picturebox :)

if anyone is interested in how to do it, this is what i do:

1. get memory for the rgb unsigned byte array
2. write the colors to it
3. convert to a "Bitmap" like this:

// choose a pixel format (here: rgb, 8 bits/color)
PixelFormat pf=Format24bppRgb;

// convert the pointer
IntPtr intptr(byte_array_rgb_pointer);

// create a pointer to a Bitmap object
Bitmap * tmpbmp = new Bitmap(xsize,ysize,xsize*channels,pf,intptr);

4. set it up for displaying in the picturebox

// now that we have converted the data to the Bitmap structure
// we can make the PictureBox display it like this
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
pictureBox1->ClientSize = System::Drawing::Size(xsize, ysize);
pictureBox1->Image = dynamic_cast<Image*>(tmpbmp);