Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

Menge
Posted

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

Posted

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...

Menge
  • 3 months later...
Posted

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 :)

Menge
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...