Is there any example to display the image from the RGB source?Thanks

  • Thread starter Thread starter linuxfedora
  • Start date Start date
L

linuxfedora

I have a function which will return the RGB source to me, then what i
want to do is to create the image and show the image on a Form. What
is the best way to do it? Is there any example for that?Thanks.
 
I have a function which will return the RGB source to me, then what i
want to do is to create the image and show the image on a Form. What
is the best way to do it? Is there any example for that?Thanks.

That depends a bit on exactly what format the RGB source is. If it is
already in a BMP format, or something that can be easily converted to
BMP format (see the Windows BITMAPFILEHEADER --
http://msdn2.microsoft.com/en-us/library/ms532321.aspx -- and related
documentation for specifics), then the simplest approach may be to just
write the data to a MemoryStream in the BMP file format, and then use
that MemoryStream as the input to Image.FromStream().

If there's a lot of conversion that you have to do anyway, it might make
more sense to create an appropriate byte array, and use the
Bitmap.LockBits() method to initialize a Bitmap (you can either use the
version that retrieves a buffer for the Bitmap into which you can copy
your data, or the version that allows you to provide the buffer which
you've already initialized from your data).

Either method will work, regardless of how much conversion there is to
do. It just seems to me that if the data basically already looks like a
BMP file (with or without the header structures), the first method could
wind up being just a handful of lines of code, justifying the possible
extra overhead of going through the whole "copy to stream, init from
stream" stuff.

But I think the second method is probably a little more efficient.
Noting, of course, that I have not done any performance testing myself
to verify that. It's just a theory. :)

Pete
 
Back
Top