-
TV static noise animation-adding random generator
Hi,
First forum posting.
I am a newbie (retired social worker) using Visual Basic 2010 Express edition and need some help with an animation for an eLearning lesson. The animation illustrates a type of white noise (like TV static) called dynamic visual noise. I've got much of the code worked out (with a lot of help) but I discovered that the speed of the animation, using this code is wrong and need some help to fix the code, get it working correctly.
You can view a Flash demo of this noise animation at http://elearningprojects.com/WN5.swf
More info here about the visual noise animation (even a Delphi source code and Windows demo): http://www.st-andrews.ac.uk/~www_sp/.../personal/jgq/
The animation has a 640 X 640 canvas, with 8 X 8 white and black dots filling it using 80 across and 80 down, for a total of 6400 dots. Some of these (approximately 400) change every second (1000 Ms) from white to black or black to white. These 400 dots need to be selected randomly every second.
The VB code I am using is missing the ability to randomly select the 400 dots per second which are the dots to be changed (white to black or black to white).
Here is the current (commented) code that needs an addition of a random generator for the 400 dots every second that will be changed:
Code:
Option Strict On
Public Class Form1
Private gDotSize As Integer = 8
Private gCanvasSize As Integer = 640
Private gDelay As Integer = 100 'ms
Private gProceed As Boolean = False
Private gImage As New System.Drawing.Bitmap(gCanvasSize, gCanvasSize)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SetClientSizeCore(gCanvasSize, gCanvasSize)
Me.Text = "Click the form to start and stop"
'Set double-buffering so that graphics may be invalidated without causing flickering.
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
If gProceed Then
gProceed = False
Else
gProceed = True
Dim vThread As New System.Threading.Thread(AddressOf GenerateStatic_Background)
With vThread
.IsBackground = True
.Name = "Thread for generating static"
End With
vThread.Start(New Object) 'You could pass an object into the thread here if you wanted.
End If
End Sub
Private Sub GenerateStatic_Background(ByVal Arg As System.Object)
'The canvas is square, so how many rows and columns will there be?
Dim vRows As Integer = Convert.ToInt32(gCanvasSize / gDotSize)
Dim vCols As Integer = Convert.ToInt32(gCanvasSize / gDotSize)
'How many dots will there be total?
Dim vTotalDots As Integer = Convert.ToInt32(vRows * vCols)
'Create blank image to draw on.
Dim vImg As New System.Drawing.Bitmap(gCanvasSize, gCanvasSize)
Using vGr As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(vImg)
'Instance random generator object and seed data.
Dim vGen As New System.Security.Cryptography.RNGCryptoServiceProvider
'Prepare an empty array of bytes which will be used to store random seed data.
'These random bytes will be converted to a 32-bit integer. Int32's are 4 bytes
'in length; therefore the array will be 4 bytes in size. Remember, when
'dimensioning static arrays, we do not specify the "length" of the array like
'in C++, but instead we specify the "upper bounds" a.k.a. the last index of
'the array, which would be 3 (0-3).
Dim vSeed(3) As Byte
'Fill the empty array with a cryptographically strong sequence of random values.
vGen.GetBytes(vSeed)
'Instance a Random object using the random bytes (converted to an integer) as a seed.
Dim vRand As Random = New Random(BitConverter.ToInt32(vSeed, 0))
'Variables for choosing the color.
Dim vCurrentRand As Integer = 0 'Black is 0; white is 1
Dim vCurrentColor As System.Drawing.Color = System.Drawing.Color.Black
'Do until told to stop by the user.
While gProceed
'Wait the desired period.
System.Threading.Thread.Sleep(gDelay)
'We will start on the first row on the left, work right across the columns, then drop
'down to the second next row (back to the left), and again work right across the
'columns, and so on...
Dim vCurrentDot As New System.Drawing.Rectangle(0, 0, gDotSize, gDotSize)
Dim vCurrentRow As Integer = 0
Dim vCurrentCol As Integer = 0
'Iterate each dot... come up with a random black or white state, and draw it to the image.
For i As Integer = 0 To vTotalDots - 1
'Generate random black or white state for this dot.
vCurrentRand = vRand.Next(0, 2) 'Either 0 or 1
If vCurrentRand = 0 Then vCurrentColor = System.Drawing.Color.Black Else vCurrentColor = System.Drawing.Color.White
'Draw this dot.
vGr.FillRectangle(New System.Drawing.SolidBrush(vCurrentColor), vCurrentDot)
'Increment the current dot for the next iteration.
vCurrentCol += 1 : vCurrentDot.X += gDotSize
If vCurrentCol = vCols Then
vCurrentCol = 0 : vCurrentDot.X = 0
vCurrentRow += 1 : vCurrentDot.Y += gDotSize
End If
Next
'Update the UI.
If Me.InvokeRequired Then
Try
Me.Invoke(New DrawUpdate_Delegate(AddressOf DrawUpdate), CType(vImg, System.Object))
Catch ex As Exception
'Error cuz you ended the program without allowing the thread to stop.
'To prevent this error, you could set gProceed = False in the Form_Closing event so the thread can end naturally.
'This Try block just prevents the error message.
End Try
Else
DrawUpdate(CType(vImg, System.Object))
End If
End While
End Using
End Sub
Private Delegate Sub DrawUpdate_Delegate(ByVal Arg As System.Object)
Private Sub DrawUpdate(ByVal Arg As System.Object)
gImage = DirectCast(Arg, System.Drawing.Bitmap)
Me.Invalidate()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImageUnscaled(gImage, 0, 0)
End Sub
End Class
I would appreciate any code suggestions to add the random generator (described above) and where to add it in the above code. It would also be a huge help if I can change the specific number of random dots so I can try values ranging from 390-400 dots per second to see which value best replicates the precise animation speed needed.
Thanks very much for your help.
Kind Regards,
saratogacoach
-
Re: TV static noise animation-adding random generator
Hard to read, without CODE TAGS
Please go back and edit your code to include tags so we can read it
-
Re: TV static noise animation-adding random generator
Hi David,
Thanks for your reply. I've now used BBcode as a FF add-on. I edited the above post using this. Hopefully, I did this correctly.
Kind Regards,
-
Re: TV static noise animation-adding random generator
Looks OK now. You can just use the ADVANCED EDITOR here at CG to click the CODE button. (#)
You can choose a Random.Net(0,400) sequence, but would have to probably choose a few patterns in advance, and switch them every second.
Look into using Dual-Buffering your screen image
-
Re: TV static noise animation-adding random generator
Hi David,
Thanks for the tip on setting up code tags. And, I'll keep in mind using double buffering.
Mindful of your comments about needing some patterns set up in advancem I wondered then if this would be truly a random 400 every 1000 ms?
I also did some online reading about random.net(), but as a beginner in VB, it's way beyond my skill level.
So, unfortunately still stuck trying to modify this code to add the random generator.
Kind Regards,
-
Re: TV static noise animation-adding random generator
Create 6-10 different bitmaps, and populate each one randomly. Then, you could fire a different one every few ms. Probably 30fps. XNA is 60fps, though
-
Re: TV static noise animation-adding random generator
Hi David,
Thank you for this suggestion. I suspect that it will not produce the smooth animation seen in the Flash demo which illustrates the "standard." I think I will need to figure out how to add the random.net feature that you mentioned earlier. Or, some timer that from the randomly selected dots does a further random selection of a maximum of 40 of these every 100 ms. Something like that. Unfortunately, my thinking is far far ahead of my ability to implement this in VB code. :-)
Kind Regards,
-
Re: TV static noise animation-adding random generator
Does it have to be coded like this? As in, is this an assignment?
Really, this is making it much more difficult on yourself. Any graphic editor can create 3 separate images of random noise. Then you just have to cycle through them in a loop. That would take you about 3 minutes to code.
-
Re: TV static noise animation-adding random generator
Hi Peej,
This is not an assignment, but the final animation has to precisely replicate the standard style, appearance and change speed for "dynamic visual noise" in order to be an effective example and exercise.
Dynamic visual noise animation can be seen in the Flash demo at:
http://elearningprojects.com/WN5.swf
and Delphi source code and a Windows demo for dynamic visual noise is at:
http://www.st-andrews.ac.uk/~www_sp/.../personal/jgq/
So, I think that a code which can randomly choose 400 dots per second, change these from white to black or black to white, on a 640X640 canvas with 80 rows across and 80 rows down of white and black dots (50% of each to start), totaling 6400 will work. The code posted above does much of this, but does not randomly select 400 per second (or 40 per 100 ms) for changing. So, the code would need to add this and change anything else in it to allow this random generator to work properly. As a beginner, I've tried to do this, but I have not been successful and need help.
But, if there is an easier design that accomplishes the same result, that would be great!
Kind Regards,
-
Re: TV static noise animation-adding random generator
the main problem is the time needed for this one line of code to complete...
Code:
vGr.FillRectangle(New System.Drawing.SolidBrush(vCurrentColor), vCurrentDot)
read the VB.net Animation article for some tips on better animation techniques..
Code:
MyGraphic.DrawRectangle(DelPen, .Location.X - 1, .Location.Y - 1, 2, 2)
Also declare your pen(or brush) outside the loop, so that it is ready to use and does not use up CPU time and memory rebuilding it for every dot.
-
Re: TV static noise animation-adding random generator
Hi,
I took a look at Richard Newcombe's animation article as suggested. As a beginner using VB, applying the new drawing method is way to complex for me.
While I understand the basic ideas, for example, moving it out of the loop, implementing this in code, where to put it, what to remove is beyond my skill level at this time.
Best Wishes,
-
Re: TV static noise animation-adding random generator
Then, you could just use the FLASH that you posted
-
Re: TV static noise animation-adding random generator
Quote:
Originally Posted by
saratogacoach
Hi,
I took a look at Richard Newcombe's animation article as suggested. As a beginner using VB, applying the new drawing method is way to complex for me.
:confused:????????:confused:
It's not a new method .. it's almost the same as the one your using..
Change your core code to look like this ... (i've highlighted key changes...)
Code:
Dim vCurrentDot As New System.Drawing.Rectangle(0, 0, gDotSize, gDotSize)
Dim vCurrentRow As Integer = 0
Dim vCurrentCol As Integer = 0
Dim vPens(2) As System.Drawing.Brush
vPens(0) = Brushes.Black
vPens(1) = Brushes.White
'Iterate each dot... come up with a random black or white state, and draw it to the image.
For i As Integer = 0 To vTotalDots - 1
'Generate random black or white state for this dot.
vCurrentRand = vRand.Next(0, 2) 'Either 0 or 1
'If vCurrentRand = 0 Then vCurrentColor = System.Drawing.Color.Black Else vCurrentColor = System.Drawing.Color.White
'Draw this dot.
vGr.FillRectangle(vPens(vCurrentRand), vCurrentDot)
'Increment the current dot for the next iteration.
vCurrentCol += 1 : vCurrentDot.X += gDotSize
If vCurrentCol = vCols Then
vCurrentCol = 0 : vCurrentDot.X = 0
vCurrentRow += 1 : vCurrentDot.Y += gDotSize
End If
Next
then at the top change the delay to 15 ms
Code:
Private gDelay As Integer = 15 'ms
now test your project...
One problem is that you has the code Sleep for 100 ms.. meaning at best you could get 10 FPS ... (not quite what you were looking for...)
reducing to 15 ms can increase it to ~ 60 FPS. However with the method your using, if all the code takes 10 ms to complete then that gets added to the 15 ms sleep time.. so you have 25 ms between Frames..
If you follow my article, the timer method explained there can also trigger every 15 ms, however the code execution time is not added to the frame time.. unless code execution time is longer than the timer.
The other thing is that using sleep functions inside loops is not the generally accepted method.
It will also eliminate the problem you put this code in for
Code:
If Me.InvokeRequired Then
Try
Me.Invoke(New DrawUpdate_Delegate(AddressOf DrawUpdate), CType(vImg, System.Object))
Catch ex As Exception
'Error cuz you ended the program without allowing the thread to stop.
'To prevent this error, you could set gProceed = False in the Form_Closing event so the thread can end naturally.
'This Try block just prevents the error message.
End Try
Else
DrawUpdate(CType(vImg, System.Object))
End If
-
1 Attachment(s)
Re: TV static noise animation-adding random generator
Okay .. i was going on the Topic title and did not initially look at the Flash demo ..
Once i saw the demo and reread the OP slowly .. i saw the problem...
So here is a small sample of what is needed using basically the methods from my article...
In the Timer interval box i've put the default of 1000 ms in but for the same/simular effect as the Flash punch in 100 and start it ...
I've also included 3 different starting displays...
Please let me know if i got it right this time .....
Gremmy...
-
Re: TV static noise animation-adding random generator
Hi,
Thank you very much for this.
I have Visual Basic 2010 Express edition (free version from MS), so I am not sure how to open and run this. So far, I extracted using 7-Zip and tried to run different files in VB 2020 Express, without getting the project to run. I can see some of the source code, but when I tried to use the project conversion wizard, it had many errors, failures to convert.
Is it possible for you to send, or tell me how to use, the code that I would place in a new Form1? Then I can use this in a new project, see if I can get it to run.
Kind Regards,
-
1 Attachment(s)
Re: TV static noise animation-adding random generator
Okay have no idea why it wont upgrade to 2010 .. I did it N.P. ...
Here is the VS 2010 ver of the same project ....
Hope this works ...
Gremmy...
-
Re: TV static noise animation-adding random generator
Hi,
Again, thanks. I am able to open these files and compile the project into an app.
Yes. If I choose random and set the interval to 120, I get the precise animation style and effect that looks like the Flash demo. Fantastic!
I will need to carefully look at the code, re-read what you've posted, to see what you've done to accomplish this, learn from it.
Much thanks!
Kind Regards,
-
Re: TV static noise animation-adding random generator
Great ... Glad it is what you were looking for....
The main reason for the first two styles was to provide a exact 50/50 spread and also where you can allow one step and count the changes..
The code is not too complicated and followed allot of what you already coded, with the difference of using a realizable picture box.
Also i rearranged some of it so that it runs better, and faster..
Note that there are no try catch blocks for incase ....... Only checking that is needed is that the text entry is numeric, however that can be taken care of with this small piece of code
Code:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
If your dont understand something, just ask .. ill try to explain it to you in laymans terms ...
-
Re: TV static noise animation-adding random generator
Hi Gremmy,
Figured out where to place this additional code. It seems to work without error.
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
I've been trying to do a few changes :
successful:
(1) increasing speed by increasing the dots changed per interval to 1000. Seems to better match the speed of the Flash and Delphi Windows demo's.
so far unsuccessful:
(2) trying to figure out (so far unsuccessfully) how to default to random and fill and (like in the Flash demo) clicking on the canvas screen to start and stop (toggle);
so far unsuccessful:
(3) setting up a 30 second default animation time-once started, runs for 30 seconds then stops.
Any suggestions, help much appreciated.
Kind Regards,
-
Re: TV static noise animation-adding random generator
ARG .. have to retype .. still getting random BANNED IP Problems...
Okay let me try again ...
#1 - dots changed per interval is calculated in this bit of code
Code:
Dotcount = CInt(400 / (1000 / Timer1.Interval))
It works like this....
400 (dots) / (per) 1000 (ms) - the actual math used is a little more than that, in that it works out the number per frame.. but i took the numbers from your original spec..
so to make it 1000 per second.. change the above line too
Code:
Dotcount = CInt(1000 / (1000 / Timer1.Interval))
#2 - Goto "Form1.vb Design" in VS .. where you now see the forms design ...
Click on the radio button that is labled 'Random'. Right click , Properties.. Scroll to Checked and set it to true. this will set random as default ...
#3 - this is a little harder than the others..
First at the top under all the other Private delcarations add
Code:
Private StartTime As Date
(just above Public sub .....)
In the Button1_click and button3_click subs .. Just after the 'Timer1.Enabled = True' add
Code:
StartTime = Date.Now
and the last one for this mod...
in the timer1_tick sub just after 'DrawPicture()' add
Code:
If StartTime.AddSeconds(30) < Date.Now Then
Timer1.Enabled = False
End If
this should stop the code after 30 seconds..
Now to trigger on a canvas click.. add this sub (same like last time)
Code:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Timer1.Interval = CInt(TextBox1.Text)
Timer1.Enabled = Not Timer1.Enabled
StartTime = Date.Now
End Sub
that should be it ....
-
Re: TV static noise animation-adding random generator
Hi Gremmy,
Thanks again.
All of changes finally went in without an error message.
At first, the following code, adding it as a Sub, gave an error message:
Code:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Timer1.Interval = CInt(TextBox1.Text)
Timer1.Enabled = Not Timer1.Enabled
StartTime = Date.Now
End Sub
error: Error 1 'Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.
I suspected this meant that there are conflicting items for PictureBox1, so I deleted:
Code:
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
With that piece of code removed, the new one substituted for it, all seems to work OK.
Again, much thanks!
Kind Regards,
-
Re: TV static noise animation-adding random generator
Hi,
I've been learning a lot and very much appreciate your help. Great progress! Getting a little more familiar with the VB UI, code window and editor.
I have been reading online about using Tracker Bars. Two of these would be useful in Form1:
(1) one slider to let the user set the length of time for the animation, ranging from a default of 30 seconds on the left (minimum) to 60 seconds on the right (maximum).
(2) a second slider, instead of a text input box, for the timer interval, ranging from a minimum of, for example, 800 ms to a maximum of, for example, 1200 ms.
While I can import 2 track bars into Form1 design, I'm not sure how to set up the code for each of these sliders to control the variables for length of time and timer interval.
I would appreciate any code suggestions. (And, once I can add these 2 track bars, I would probably need to figure out how to not only delete the text input box, any other irrelevant controls, but also any other old code that would now conflict with these new controls to govern these variables. Big challenge.)
I would welcome any suggestions on adding these, their code, and making this work without conflicts/errors.
Thanks very much.
Kind Regards,
-
Re: TV static noise animation-adding random generator
Use both (for now). Have the SLIDER UPDATE EVENT in the Text Event, and vice-versa. When you move the slider, the text will update.
Also, set the upper and lower bounds of the slider, and use the same / as before, to come up with a % of the total range desired. Display the % in the textbox
-
Re: TV static noise animation-adding random generator
Right this time you can make the changes .. i will guide you along you way...
#1 - Remove the Textbox from the form ... Right click - 'delete' (you will get a few errors about textbox1 not been defined, dont worry about them right now)
#2 - Add a slider (trackbar) to the form, right click and select 'properties' .. Name it TBinterval... change the minimum value to 100 and maximum value to 1000
#3 - Now find in the code all the lines that have
Code:
Timer1.Interval = CInt(TextBox1.Text)
and change them to
Code:
Timer1.Interval = TBinterval.Value
The errors you had before should be clearing as you change each one ...
#4 - delete the sub 'Private Sub TextBox1_KeyPress' as it is no longer needed (all 5 lines up to 'End Sub') .. this should take care of the last error....
#5 - Add another Trackbar to the form, right click - 'properties' ... Name it TBTime... change the minimum value to 30 and maximum value to 60
#6 - now find in the code the line that has
Code:
If StartTime.AddSeconds(30) < Date.Now Then
and change it to
Code:
If StartTime.AddSeconds(TBTime.Value) < Date.Now Then
this should take care of the changes needed to ad the sliders into the project ..
no other code needs to be changed or removed ..
-
Re: TV static noise animation-adding random generator
Hi Gremmy,
Thanks again. I was able to make these changes successfully.
Continuing to better understand how to make things happen, add, delete, change controls and code.
Much thanks!
Kind Regards,
-
Re: TV static noise animation-adding random generator
Here's one that's 15 times faster - sorry it's a bit late being posted!
Code:
Option Strict On
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class Form1
Public Class syncObject
Public Sub New()
End Sub
End Class
Public syncOb As New syncObject()
Public Declare Sub AttachConsole Lib "Kernel32" (ByRef dwProcessId As Long)
Private Const ATTACH_PARENT_PROCESS As Integer = -1
Private WithEvents timer As System.Windows.Forms.Timer
Private frameCount As UShort = 0US
Private gCanvasWidth As UShort = (500US \ 8) * 8
Private gCanvasHeight As UShort = 300US
Private gDelay As Integer = 1 'ms
Private gProceed As Boolean = False
Private gImage As New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
gProceed = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SetClientSizeCore(gCanvasWidth, gCanvasHeight)
Me.Text = "Click the form to start and stop"
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
AttachConsole(ATTACH_PARENT_PROCESS)
timer = New Timer()
timer.Interval = 1000
timer.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
Console.WriteLine("FPS: " & frameCount)
frameCount = 0
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
If gProceed Then
Me.FormBorderStyle=Windows.Forms.FormBorderStyle.Sizable
Me.WindowState=FormWindowState.Normal
gProceed = False
Else
Me.FormBorderStyle=Windows.Forms.FormBorderStyle.None
Me.WindowState=FormWindowState.Maximized
gCanvasWidth =CUShort((Me.Width \ 8) * 8)
gCanvasHeight= CUShort(Me.height)
gImage = New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
gProceed = True
Dim vThread As New System.Threading.Thread(AddressOf GenerateStatic_Background)
vThread.IsBackground = True
vThread.Name = "Thread for generating static"
vThread.Start(New Object)
End If
End Sub
Private Delegate Sub DrawUpdate_Delegate(ByVal Arg As System.Object)
Private Sub DrawUpdate(ByVal Arg As System.Object)
gImage = DirectCast(Arg, System.Drawing.Bitmap)
Me.Invalidate()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
SyncLock (syncOb)
e.Graphics.DrawImageUnscaled(gImage, 0, 0)
End SyncLock
End Sub
'Super fast speed static thread!
Private Sub GenerateStatic_Background(ByVal Arg As System.Object)
Dim vImg As New System.Drawing.Bitmap(gCanvasWidth, gCanvasHeight, PixelFormat.Format1bppIndexed)
Dim bounds As Rectangle = New Rectangle(0, 0, vImg.Width, vImg.Height)
Dim m_BitmapData As System.Drawing.Imaging.BitmapData = vImg.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format1bppIndexed)
Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
vImg.UnlockBits(m_BitmapData)
Dim ImageBytes(total_size) As Byte
Dim vGen As New System.Security.Cryptography.RNGCryptoServiceProvider
Dim vSeed(3) As Byte
vGen.GetBytes(vSeed)
Dim vRand As Random = New Random(BitConverter.ToInt32(vSeed, 0))
While gProceed
frameCount += 1US
If frameCount Mod 5 = 1 Then System.Threading.Thread.Sleep(gDelay)
SyncLock (syncOb)
m_BitmapData = vImg.LockBits(bounds, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format1bppIndexed)
vRand.NextBytes(ImageBytes)
Marshal.Copy(ImageBytes, 0, m_BitmapData.Scan0, total_size)
vImg.UnlockBits(m_BitmapData)
End SyncLock
Try
Me.Invoke(New DrawUpdate_Delegate(AddressOf DrawUpdate), CType(vImg, System.Object))
Catch e As Exception
End Try
End While
End Sub
End Class