Tor Henrik Hovi Posted August 27, 2003 Posted August 27, 2003 I recive an array of bytes from a USB 2.0 device. The array is a 800x600 grayscale picture. The array is named Buffer I use this code to present the image: Private Sub BuildImage() Dim Gray As Byte Dim c, x, y As Integer c=0 For y = 0 To 599 For x = 0 To 799 Gray = Buffer© VideoBitmap.SetPixel(x, y, Color.FromArgb(Gray, Gray, Gray)) c = c + 1 Next Next End Sub I takes about .5 sec to complete this on my PC. Wich gives me a frame rate of 2 pictures per sec. I'm looking for a faster way of displaying the picture. Probably setpixel is not the fastest way? As you see I have to make a RGB code for the grayscale Color.FromArgb(Gray, Gray, Gray). Is there some way of inserting the grayscale values directly? Thanx in advance :D Quote
*Gurus* divil Posted August 27, 2003 *Gurus* Posted August 27, 2003 You might want to check out the various constructors for the Bitmap class. One of them accepts a pointer to raw data as one of its parameters, and would certainly be the best way of doing what you're trying to do, if you can get it working. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Menge Posted August 29, 2003 Posted August 29, 2003 i agree with divil on the solution. all u need is a pointer to the array start. and then it goes smooth from there... with framerates about 10fps i think Quote Menge
Tor Henrik Hovi Posted August 29, 2003 Author Posted August 29, 2003 OK guys! Thanx allot for your answers, butI could not make it work. So to test this I created a new form, slapped on a PictureBox and wrote this code: Dim Buffer As Byte() Dim VideoBitmap As Bitmap Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim x, y, c As Integer ReDim Buffer(480000) c = 1 For y = 1 To 600 For x = 1 To 800 Buffer(c) = CByte(255 / 800 * x) c = c + 1 Next Next End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click Dim BufferPointer As IntPtr Dim Stride As Integer BufferPointer = Nothing 'How do I get a pointer ro an Array? Stride = 800 * 8 'What is Stride?? VideoBitmap = New Bitmap(800, 600, Stride, Drawing.Imaging.PixelFormat.Format8bppIndexed, BufferPointer) VideoBitmap.MakeTransparent() PictureBox1.Refresh() End Sub Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint e.Graphics.DrawImage(VideoBitmap, 0, 0, PictureBox.Width, PictureBox.Height) End Sub Now I've got a few moe questions; How do I get a pointer to my Array (Buffer)? What is Stride?? (The memory size of a row in the stream of pixel data???) (I just took the number of pixels in a row and multiplied with eight since they are byte?? Probably wrong.) Please take the time to answer my stupid questions Quote
Menge Posted August 29, 2003 Posted August 29, 2003 u could try this: on System.Runtime.InteropServices.Marshal [C#] public static void Copy( byte[] source, int startIndex, IntPtr destination, int length ); it copies an array of bytes to a pointer. dunno if its the best... but... Quote Menge
pagis Posted December 12, 2003 Posted December 12, 2003 but its a 2 dim byte array The Marshal.Copy deals with 1 dim byte array. so how can you load a 2 Dim byte array into a pointer ? Quote
Menge Posted December 12, 2003 Posted December 12, 2003 hrm... the image's Stride is the size of a line of the image in Bytes. (800x600 image at 32bpp = stride of 800pixels * (32bits/8bitsperbyte)) hope this helps :) Quote Menge
dannyres Posted December 13, 2003 Posted December 13, 2003 Not sure if this would work but you could try it... Dim memory As New IO.MemoryStream(ByteArray) Dim bmp As New Bitmap(memory) memory.Close() Quote
Dark Kai Posted December 17, 2003 Posted December 17, 2003 Try looking to this http://www.xtremedotnettalk.com/t74789.html Quote
predseda Posted January 10, 2004 Posted January 10, 2004 I have the same problem like Tor Henrik Hovi, I saw Dark Kai's url http://www.xtremedotnettalk.com/t74789.html , it works good but the code is little bit chaotic for me. I am looking for something easyer. Only redraw the array to the picturebox. That's all. Please help. Thanks a lot. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.