473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

byte[,,] to Bitmap?

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

Nov 17 '05 #1
5 5835
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.

<ma*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 17 '05 #2
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]
- mv*@spam.guard.caspershouse.com

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uy*************@TK2MSFTNGP09.phx.gbl...
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.

<ma*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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


Nov 17 '05 #3
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

Nov 17 '05 #4
I've readed MSDN help and thought a little ;) I think I've almost
solved the problem

Thanx a lot

Nov 17 '05 #5
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.

<ma*********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eka Gautama | last post by:
Hi all, I need help for a sample code to convert a bitmap to byte as well from byte to bitmap.. Thanks for the help Eka
1
by: James Dean | last post by:
Could somebody tell me a quick way to write a whole byte array to a 1 bit per pixel bitmap if its possibleinstead of locking the bits and doing it like that..... *** Sent via Developersdex...
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
2
by: Soja | last post by:
How can i create a Bitmap from a rawbuffer-BYTE* (from framegrapper). I do following: Bitmap *myBit2 = new Bitmap(wImage,hImage,wImage*sizeof(BYTE),PixelFormat::Format8bppIndexed...
9
by: Sharon | last post by:
I'm trying to convert an Image file to a byte array . Later in my code I'm trying to create a new Image from this byte array as a restored Image. But when I try to save the restored Image to a...
1
by: Sharon | last post by:
I have 2 questions that are just the opposite to one another: (1) I need to read an image file (like bitmap, jpeg etc.) and to save only its data, I need to save his data in a raw data format,...
2
by: perspolis | last post by:
Hi all I want to convert an Image to byte. I used TypeDescriptor to get a convertor.. it sometimes works and sometimes gives me "GDI+ error".. how can I convert image to bye ?? thanks
3
by: pamelafluente | last post by:
I am trying to convert in C# a VB.NET routine (which probably came from C# ! ) I need to translate using pointers (this should get the Alpha byte in a 32bppPArgb bitmap): Function...
1
by: trevor.farchild | last post by:
Hi, long time reader, first time poster I have an application that will be doing this 5 times a second: Get a bunch of data from a NetworkStream and convert it into a Bitmap Therefore, the...
0
by: Oriane | last post by:
Hello there, I try to handle bitmap images stored in an Image column in Sql Server. The following code is ok when the image is of type Bitmap (*.bmp): private ImageSource...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.