473,320 Members | 1,724 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,320 software developers and data experts.

RGB into a picturebox

I'm using RoboRealm to get an image from a webcam. the roborealm docs
say to do something like
byte[] image = new byte[d.width * d.height];
Dimension dd = rr.getImage(image, d.width * d.height);

to get the image. the docs call the image an "RGB triplet". how can I
display this in a picturebox?

Small wods please, I'm a HW guy :-)

Ringo

May 16 '07 #1
1 3069
On Wed, 16 May 2007 13:42:58 -0700, Ringo <ri*********@gmail.comwrote:
I'm using RoboRealm to get an image from a webcam. the roborealm docs
say to do something like
byte[] image = new byte[d.width * d.height];
Dimension dd = rr.getImage(image, d.width * d.height);

to get the image. the docs call the image an "RGB triplet". how can I
display this in a picturebox?
To display in a picture box control, you need a Bitmap instance. You can
use the LockBit() and UnlockBits() methods to get access to the underlying
data for the bitmap (LockBits()), copy the byte array you've retrieved to
the underlying data, and then signal that you're done with the data
(UnlockBits()).

Note that while the example code in the MSDN documentation does not appear
to concern itself with the Stride value of the BitmapData class, it's not
at all clear to me that's correct. Typically, you'd have to use the
Stride value to calculate the start of each new row of bitmap data,
because internally bitmaps have rows of data rounded in length rounded up
to ensure that each row is on an aligned memory address (usually aligned
on 16-bit boundaries for regular Windows bitmaps).

In other words, rather than just copying the entire "image" array to the
Scan0 address in the BitmapData class (as demonstrated in the sample code
on MSDN), you really should only copy one row of data at a time,
calculating a new destination address by adding Stride to the previous
row's starting address (starting with Scan0 of course).

Finally, you need to make sure you're using the right kind of bitmap
data. It sounds as though your RoboRealm library is returning 24-bit
image data, and so as long as you create a Bitmap with that format, you
should be able to essentially copy the data directly.

All that said, I haven't played with the .NET version of this at all, so
you may find that it's actually providing more automatic functionality
than I am assuming. For example, there's a possibility that you could
just use the LockBits() method that includes a BitmapData instance as
input with the ImageLockMode flags set to include UserInputBuffer. As
long as you properly describe your input data (24-bits, Scan0 pointing to
an unsafe version of your array, Stride set to the actual length between
rows of your array), it may be that would just work directly without you
having to copy data. I'm not sure.

The above is the basic idea. If the specifics aren't exactly right, it
should at least get you pointed in the right direction.

Pete
May 16 '07 #2

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

Similar topics

0
by: SamSpade | last post by:
I have a usercontrol that contains a picturebox. The user can obtain (creategraphics) a picturebox graphics object and draw on the picturebox. She could do gr.GraphincInit.Millimeter and then draw...
0
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
2
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
4
by: Jerry West | last post by:
I have a routine that updates a PictureBox image every x seconds. I do this by first loading an array with the path to all of the images. I then generate a random number to use as the index of the...
4
by: munibe | last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small...
3
by: kirk | last post by:
I have a form with a PictureBox control on it. The .Image property is set to a PNG file(which shows the picture of the US map) with some transparency in it. The .BackColor property is set to...
4
by: Jim McGivney | last post by:
In C# on Form1 I genetate an array of PictureBoxes and populate each with an image as seen in the code below. Later on I want to access a specific PictureBox to change its image, but I keep...
5
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
1
by: leshka82 | last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.