PC Review


Reply
Thread Tools Rate Thread

byte[,,] to Bitmap?

 
 
mallolnolla@gmail.com
Guest
Posts: n/a
 
      11th Oct 2005
Hello there,

I'm trying to display a grabbed picture from a matrox meteor II to a
picturebox (I know I can use the matrox display, but I need to show it
on a PictureBox). I've tried to fill the bitmap with the setpixel
method, but it's too much slow (my camera's resolution is about 700x500
pixels).

Does anybody know how to fill the bitmap from a 3-dimensional array
(width x height x R/G/B), or even 3 2-dimensional arrays?

Any help would be greeted.

I've been searching for information through the internet, but I didn't
find the appropiate solution.

Thanks a lot

 
Reply With Quote
 
 
 
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      11th Oct 2005
I would suggest creating a bitmap of the same size and using LockBits to
enable you to iterate the three dimensional array and transfer that info to
the individual bytes of the bitmap.

See the GDI+ FAQ for detailed info on LockBits.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello there,
>
> I'm trying to display a grabbed picture from a matrox meteor II to a
> picturebox (I know I can use the matrox display, but I need to show it
> on a PictureBox). I've tried to fill the bitmap with the setpixel
> method, but it's too much slow (my camera's resolution is about 700x500
> pixels).
>
> Does anybody know how to fill the bitmap from a 3-dimensional array
> (width x height x R/G/B), or even 3 2-dimensional arrays?
>
> Any help would be greeted.
>
> I've been searching for information through the internet, but I didn't
> find the appropiate solution.
>
> Thanks a lot
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      11th Oct 2005
Even better, if your environment allows, use unsafe code. The three
dimensional array that you have should be one contiguous block in memory,
and you can cast that to a byte*, and copy the elements using CopyMemory (by
just passing pointers).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:(E-Mail Removed)...
>I would suggest creating a bitmap of the same size and using LockBits to
>enable you to iterate the three dimensional array and transfer that info to
>the individual bytes of the bitmap.
>
> See the GDI+ FAQ for detailed info on LockBits.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consulting
> http://www.ramuseco.com
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hello there,
>>
>> I'm trying to display a grabbed picture from a matrox meteor II to a
>> picturebox (I know I can use the matrox display, but I need to show it
>> on a PictureBox). I've tried to fill the bitmap with the setpixel
>> method, but it's too much slow (my camera's resolution is about 700x500
>> pixels).
>>
>> Does anybody know how to fill the bitmap from a 3-dimensional array
>> (width x height x R/G/B), or even 3 2-dimensional arrays?
>>
>> Any help would be greeted.
>>
>> I've been searching for information through the internet, but I didn't
>> find the appropiate solution.
>>
>> Thanks a lot
>>

>
>



 
Reply With Quote
 
mallolnolla@gmail.com
Guest
Posts: n/a
 
      11th Oct 2005
Thank you all for your quick reply. I've tried the LockBit option
(using unsafe code anyway), but I've another problem:
to set a pixel value, I don't have enough space using a byte, because
I've three bytes for every pixel (R, G and B). How do I set a pixel
value on the bitmap then? Using one byte per pixel only allows me to
have a grayscale picture, and I need a color one.

Thank you again

 
Reply With Quote
 
mallolnolla@gmail.com
Guest
Posts: n/a
 
      11th Oct 2005
I've readed MSDN help and thought a little I think I've almost
solved the problem

Thanx a lot

 
Reply With Quote
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      11th Oct 2005
You have obviously misunderstood the way LockBits works. Take a look at my
explanation and pay attention to the different layouts for the different
pixel formats. You will see that the full pixel depth is catered for.

It's unlikely your array will have the required stride so it will only be by
coincidence that you can copy the memory to the BitmapData buffer directly
as Nick suggests.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you all for your quick reply. I've tried the LockBit option
> (using unsafe code anyway), but I've another problem:
> to set a pixel value, I don't have enough space using a byte, because
> I've three bytes for every pixel (R, G and B). How do I set a pixel
> value on the bitmap then? Using one byte per pixel only allows me to
> have a grayscale picture, and I need a color one.
>
> Thank you again
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert a Bitmap to a byte[] Bill Fuller Microsoft C# .NET 1 7th Jun 2008 04:00 AM
Convert a Bitmap to a Byte Array? =?Utf-8?B?Q29udmVydCBhIEJpdG1hcCB0byBhIEJ5dGUgQXJy Microsoft Dot NET Compact Framework 4 20th Oct 2005 04:04 PM
Convert Bitmap to Byte[] Sergio Florez M. Microsoft C# .NET 4 2nd Jul 2004 10:49 PM
VB .NET Bitmap to byte array saima ashraf Microsoft Dot NET Compact Framework 1 31st Dec 2003 12:43 AM
Convert Bitmap to Byte and Byte to Bitmap Eka Gautama Microsoft C# .NET 2 11th Nov 2003 04:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.