graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
Go Back  Xtreme Visual Basic Talk > > > graphics in picturebox keeps getting erased


Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2013, 12:55 PM
zecharia zecharia is offline
Newcomer
 
Join Date: Nov 2013
Posts: 3
Default graphics in picturebox keeps getting erased


Code below
Code:
Me.Invoke(Sub()


                      Dim Red5 As New Pen(Color.FromArgb(255, 0, 0, 0))

                      Dim thmb = New Bitmap(CInt(PictureBox1.Width), CInt(PictureBox1.Height))
                      Dim graph2 As Graphics = Graphics.FromImage(thmb)

                      graph2.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
                      graph2.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

                      If samplenr > PictureBox1.Width Then
                          graph2.Clear(Color.White)
                          samplenr = 1
                          oldsamplenr = 0
                      End If

                      d = PictureBox1.Height
                      d = d / 2
                      bb = c * PictureBox1.Height / 3 + d
                      cc = oldsample * PictureBox1.Height / 3 + d
                      e = oldsamplenr
                      f = samplenr


                      graph2.DrawLine(Red5, e, cc, f, bb)


                      If File.Exists("c:\tempbitmap.jpg") Then
                          Kill("c:\tempbitmap.jpg")
                      End If

                      thmb.RotateFlip(RotateFlipType.RotateNoneFlipY)

                      PictureBox1.Image = thmb

                      Try
                          thmb.Save("c:\tempbitmap.jpg")
                      Catch ex As Exception
                      End Try
                      samplenr += 1
                      oldsamplenr += 1
                      oldsample = c
                  End Sub)
this code is in the receive UART sub. I use the picture box to display data received to form a graph. It is ok so far that each data point is displayed, but the old one keeps getting erased when the new one is to be written. Also, the old x component seems to be set at 0, even thought tracing it using a breakpoint reveals that it counts up properly.
Anyone got a clue?
Appreciate all suggestions, since I'm new to this kind of handling.l usually work with C in embedded projects.

Last edited by passel; 11-29-2013 at 02:20 PM.
Reply With Quote
  #2  
Old 11-29-2013, 02:54 PM
passel's Avatar
passelgraphics in picturebox keeps getting erased passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

Well, as far as I can tell, it looks like you are adding a line segment each time this sub is executed.
But, you are also doing something in the sub that doesn't make sense if you're trying to build up a picture a segment at a time.

Dim thmb = New Bitmap(CInt(PictureBox1.Width), CInt(PictureBox1.Height))

This will create an empty bitmap each time you execute the sub, so I'm not sure how you would expect to have any previously drawn data if you start with an empty bitmap each time.

Perhaps you want to create the bitmap in the main form so it exists the whole time you run you application.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 11-29-2013, 04:21 PM
zecharia zecharia is offline
Newcomer
 
Join Date: Nov 2013
Posts: 3
Default

Hi, moving it out of the current sub causes InvalidOperationException
such as placing it either in LoadForm or in the global part.
I've tried various schemes such as naming it Me.thmb, but nothing works.
Any suggestion how get around this? I understand your point that having
it where it was will recreate it every time, but I saved data (or so i thought) in a global area and there nothing seems to stick. When extracting data it is all zero. Only the new data has the proper value. I hoped by saving all data
in a table I could get them back and reprint them. But no.
This is like:
grafdata(index)=sample
and index is added one by each sample. These are both global values. But it always contain zero values. So I must be doing some wrong here.
Guesses?
Reply With Quote
  #4  
Old 11-29-2013, 04:59 PM
zecharia zecharia is offline
Newcomer
 
Join Date: Nov 2013
Posts: 3
Default

Solved by moving index for table from global store to local store. Then I could access the data and redraw at every new data. Also I made a mistake by trying to to save the value 0.052 into an integer...By using the actual screen value in the table all seems to work.
Reply With Quote
Reply

Tags
vb graphics picturebox


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
 
graphics in picturebox keeps getting erased
graphics in picturebox keeps getting erased
 
-->