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

How do I clear a FillEllipse without clearin the graphics of my image

kspiros
16
I have a picture box which contains an image and some drawn ellipses. while a thread pass by the ellipses increase the alpha of the ellipse but when the tread leaves the ellipse range i can't change the alpha value because it paints it over. how can I erase only the ellipse without touching anything else in the image.
image linksimage1 image2

my code

Expand|Select|Wrap|Line Numbers
  1. public void work()
  2.         {
  3.  
  4.             Graphics xGraph;
  5.  
  6.             xGraph = Graphics.FromImage(pictureBox_Map.Image);
  7.  
  8.                 for (int i = 0; i < 5; i++)
  9.                 {
  10.  
  11.                     Thread.Sleep(draw_delay);
  12.  
  13.                     double a;
  14.                     a = Math.Sqrt(Math.Pow(pointcheck[0] - X[i], 2) + Math.Pow(pointcheck[1] - Y[i], 2));
  15.                     int d = Convert.ToInt32(a);
  16.  
  17.                     if (Math.Abs(d) < R[i])
  18.                     {
  19.                         if ((elegxos[i] == 0) && (change[i] == false))
  20.                         {
  21.  
  22.                             SolidBrush Brush = new SolidBrush(Color.FromArgb(255, Red[i], Green[i], Blue[i]));
  23.  
  24.                             pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
  25.                             elegxos[i] = 1;
  26.                             this.Invalidate();
  27.                             change[i] = true;
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         SolidBrush Brush = new SolidBrush(Color.FromArgb(50, Red[i], Green[i], Blue[i]));
  33.  
  34.                         pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
  35.                         this.Invalidate();
  36.                         change[i] = false;
  37.                     }    
  38.  
  39.                 }
  40.                 xGraph.Dispose();
  41.  
  42.                 this.Invalidate();
  43.         }
Oct 31 '08 #1
10 2044
Plater
7,872 Expert 4TB
Don't keep drawing the elipse?
Oct 31 '08 #2
tlhintoq
3,525 Expert 2GB
I have a picture box which contains an image and some drawn ellipses. while a thread pass by the ellipses increase the alpha of the ellipse but when the tread leaves the ellipse range i can't change the alpha value because it paints it over. how can I erase only the ellipse without touching anything else in the image.
image linksimage1 image2

my code

Expand|Select|Wrap|Line Numbers
  1. public void work()
  2.         {
  3.  
  4.             Graphics xGraph;
  5.  
  6.             xGraph = Graphics.FromImage(pictureBox_Map.Image);
  7.  
  8.                 for (int i = 0; i < 5; i++)
  9.                 {
  10.  
  11.                     Thread.Sleep(draw_delay);
  12.  
  13.                     double a;
  14.                     a = Math.Sqrt(Math.Pow(pointcheck[0] - X[i], 2) + Math.Pow(pointcheck[1] - Y[i], 2));
  15.                     int d = Convert.ToInt32(a);
  16.  
  17.                     if (Math.Abs(d) < R[i])
  18.                     {
  19.                         if ((elegxos[i] == 0) && (change[i] == false))
  20.                         {
  21.  
  22.                             SolidBrush Brush = new SolidBrush(Color.FromArgb(255, Red[i], Green[i], Blue[i]));
  23.  
  24.                             pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
  25.                             elegxos[i] = 1;
  26.                             this.Invalidate();
  27.                             change[i] = true;
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         SolidBrush Brush = new SolidBrush(Color.FromArgb(50, Red[i], Green[i], Blue[i]));
  33.  
  34.                         pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
  35.                         this.Invalidate();
  36.                         change[i] = false;
  37.                     }    
  38.  
  39.                 }
  40.                 xGraph.Dispose();
  41.  
  42.                 this.Invalidate();
  43.         }
I need to make sure I understand what it is you're trying to do.

You have a graphic. The streetmap background for example.
Then you are painting onto it the various ellipses that represent different signals, such as WiFi.
Later, you want to take away the ellipses you painted and have your background street map still intact, and not have big holes in from your ellipses.
Does that sound right?

You can't really. If you only have one graphic in memory, and you change it, then you've changed it. There is nothing holding the data that used to be there before you changed it.

I think you will have to make a more significant change to your program in order to restore the underlying graphic. You can't just draw on your base and forget where/what was done and try to figure it out in a later method.

I think you will have better luck if you actually keep track of the drawn ellipses as objects. Create a "Signal" Class with properties like SignalType, SignalCenter, SignalRange etc. Give the class methods for drawing itself, and other basic functionality. Then for each signal create an instance of the class and stick them in an array. A SignalClass[ ].

Now you can call
Expand|Select|Wrap|Line Numbers
  1. mySignalClassArray[3].SetSignalAs(ENUMERATEDSIGNAL_WIFI);
  2. mySignalClassArray[3].SetCenter(50,200);// Point x, Point y
  3. mySignalClassArray[3].SetRange(45);// 1 pixel = 1 map scale foot
  4. mySignalClassArray[3].DrawEllipse(nSignalStregth);//Weak signal becomes more transparant
  5.  

If you keep one copy of the base street map in memory you can use it as a source to copy from.

So you make a new copy of the map to a graphic in memory,
Loop through all your SignalArray iterations painting ellipses,
Replace the displayed graphic with your newly created graphic.
pause
repeat with a fresh map background.

Your signals will then appear to move, fade in strength or dissappear all together depending on the values you feed them.

Later when you want to change behavior, you only have to change the SignalClass one time, one place. If you find a better way to do the replace your update doesn't have to become a nightmare. If you want to add a sound effect to taking away the signal, no big deal.

Your mantra is... "Small discrete methods that have one task. Not massive methods that try to do everything."

Its easier to create a behavior by calling methods in the order:
A, B, C, D, E

Then later get an all new behavior by just changing the order to:
A, B, E, D, C

If all those methods exist as a complex set of If... else... switch clauses it is much harder to make a second behavior that is close to the first, but not quite. You have to copy that entire big method and make changes. Now you have two nearly identical methods to keep changes synchronized.

Sorry if I got a little side tracked. The goal after all is better code practices in general and not just the shortest answer to the question, if that answer is just going to create a bigger nightmare for you later down the line.
Oct 31 '08 #3
kspiros
16
Don't keep drawing the elipse?
How can i dispose it?
Nov 1 '08 #4
kspiros
16
I need to make sure I understand what it is you're trying to do.

You have a graphic. The streetmap background for example.
Then you are painting onto it the various ellipses that represent different signals, such as WiFi.
This is correct, this what I am trying to do
Later, you want to take away the ellipses you painted and have your background street map still intact, and not have big holes in from your ellipses.
Does that sound right?
I am trying not to take away all the ellipses at the same time. I will explain . I have a map in a picture box in this picture box i can click only twice and only in the roads then a thread is painting the road between the first and the second click. What I mean is it starts from the first click and slowly draws the road to the second click as a gps of a car. While lets say driving it passes by from various networks with different capabilities each. What i am trying to show is when lets say the car is in range i increase the alpha of the network and when is out of rage i decrease it. The problem is that i can not dispose any ellipse i want without touching the image.
You can't really. If you only have one graphic in memory, and you change it, then you've changed it. There is nothing holding the data that used to be there before you changed it.

I think you will have to make a more significant change to your program in order to restore the underlying graphic. You can't just draw on your base and forget where/what was done and try to figure it out in a later method.

I think you will have better luck if you actually keep track of the drawn ellipses as objects. Create a "Signal" Class with properties like SignalType, SignalCenter, SignalRange etc. Give the class methods for drawing itself, and other basic functionality. Then for each signal create an instance of the class and stick them in an array. A SignalClass[ ].
I have everything in my database
Now you can call
Expand|Select|Wrap|Line Numbers
  1. mySignalClassArray[3].SetSignalAs(ENUMERATEDSIGNAL_WIFI);
  2. mySignalClassArray[3].SetCenter(50,200);// Point x, Point y
  3. mySignalClassArray[3].SetRange(45);// 1 pixel = 1 map scale foot
  4. mySignalClassArray[3].DrawEllipse(nSignalStregth);//Weak signal becomes more transparant
  5.  

If you keep one copy of the base street map in memory you can use it as a source to copy from.
What do you mean?
So you make a new copy of the map to a graphic in memory,
Loop through all your SignalArray iterations painting ellipses,
Replace the displayed graphic with your newly created graphic.
pause
repeat with a fresh map background.

Your signals will then appear to move, fade in strength or dissappear all together depending on the values you feed them.

Later when you want to change behavior, you only have to change the SignalClass one time, one place. If you find a better way to do the replace your update doesn't have to become a nightmare. If you want to add a sound effect to taking away the signal, no big deal.

Your mantra is... "Small discrete methods that have one task. Not massive methods that try to do everything."

Its easier to create a behavior by calling methods in the order:
A, B, C, D, E

Then later get an all new behavior by just changing the order to:
A, B, E, D, C

If all those methods exist as a complex set of If... else... switch clauses it is much harder to make a second behavior that is close to the first, but not quite. You have to copy that entire big method and make changes. Now you have two nearly identical methods to keep changes synchronized.

Sorry if I got a little side tracked. The goal after all is better code practices in general and not just the shortest answer to the question, if that answer is just going to create a bigger nightmare for you later down the line.
[/quote]
I will give you more photos. I am not very good in graphics because it is the first time i use them image3 image4 image5
Nov 1 '08 #5
tlhintoq
3,525 Expert 2GB
This is correct, this what I am trying to do

I am trying not to take away all the ellipses at the same time. I will explain . I have a map in a picture box in this picture box i can click only twice and only in the roads then a thread is painting the road between the first and the second click. What I mean is it starts from the first click and slowly draws the road to the second click as a gps of a car. While lets say driving it passes by from various networks with different capabilities each. What i am trying to show is when lets say the car is in range i increase the alpha of the network and when is out of rage i decrease it. The problem is that i can not dispose any ellipse i want without touching the image.

I have everything in my database

What do you mean?


I will give you more photos. I am not very good in graphics because it is the first time i use them image3 image4 image5
I kinda had a feeling this was the direction of the project based on the graphics you posted with the street map and the various signal types in the legend of the graphic.

Let me try rephrasing the suggestions of the earlier post.

Quit thinking you are going to keep just one image on screen.
Instead, consider posting a new image on screen once per second.
You don't have to "undo" what you've already painted. Just replace one graphic with an updated graphic.

You can use a Timer for this. Each time the timer ticks it will call a function such as MakeNewMap(), then put a newly created image in your picture box.
Expand|Select|Wrap|Line Numbers
  1. Bitmap myTempMap = null;// member variable
  2. Bitmap BaseMapImage = null; // set this to your street map so you always have a clean copy of it to use later
  3. MakeNewMap()
  4. {
  5.      myTempMap = BaseMapImage;
  6.      UpdateWiFi();// This method will draw an ellipse for the WiFi signal
  7.      UpdateWiMax();// This method will draw an ellipse for the WiMax signal
  8.      UpdateUMTS();// you get the drift
  9.  
  10. }
  11. private void timer1_Tick(object sender, System.EventArgs e)
  12.  {
  13.      MakeNewMap();
  14.      pictureBox_map.Image = myTempMap;
  15. }
  16.  
Nov 2 '08 #6
kspiros
16
I kinda had a feeling this was the direction of the project based on the graphics you posted with the street map and the various signal types in the legend of the graphic.

Let me try rephrasing the suggestions of the earlier post.

Quit thinking you are going to keep just one image on screen.
Instead, consider posting a new image on screen once per second.
You don't have to "undo" what you've already painted. Just replace one graphic with an updated graphic.

You can use a Timer for this. Each time the timer ticks it will call a function such as MakeNewMap(), then put a newly created image in your picture box.
Expand|Select|Wrap|Line Numbers
  1. Bitmap myTempMap = null;// member variable
  2. Bitmap BaseMapImage = null; // set this to your street map so you always have a clean copy of it to use later
  3. MakeNewMap()
  4. {
  5.      myTempMap = BaseMapImage;
  6.      UpdateWiFi();// This method will draw an ellipse for the WiFi signal
  7.      UpdateWiMax();// This method will draw an ellipse for the WiMax signal
  8.      UpdateUMTS();// you get the drift
  9.  
  10. }
  11. private void timer1_Tick(object sender, System.EventArgs e)
  12.  {
  13.      MakeNewMap();
  14.      pictureBox_map.Image = myTempMap;
  15. }
  16.  
thank you these was extremely helpful!!! thanks a lot!!!
Nov 5 '08 #7
kspiros
16
I have another problem now. the circles are not painted in the exact location which I want them to. For example, I want to paint them in coordinates lets say x=200
y=200 and r=200, that is why i use
Expand|Select|Wrap|Line Numbers
  1. xGraph.FillEllipse(Brush, 200, 200, 200,200);
but in the picture it does not go exactly on the point (200,200) of the picture with exactly r=200 but instead goes to about (300,300) with r=100. How can i solve this?
Nov 5 '08 #8
Plater
7,872 Expert 4TB
The dimensions that you supply to the drawing are not the center point but the bounding rectangle, have you been formulating for that?
Nov 5 '08 #9
kspiros
16
The dimensions that you supply to the drawing are not the center point but the bounding rectangle, have you been formulating for that?
you are correct i did not notice that it was the diameter. i can fix that by putting 2*r
Expand|Select|Wrap|Line Numbers
  1. xGraph.FillEllipse(Brush, 200, 200,2* 200,2*200); //2*200=2*r
how can i use them to put the center? By saying bounding rectangle what do you mean what x and y means?
Nov 6 '08 #10
kspiros
16
I found the reason why these is the answer!!!
Expand|Select|Wrap|Line Numbers
  1. xGraph.FillEllipse(Brush, X - R, Y - R, 2 * R, 2 * R);
Thanks a lot for all your help!!!
Nov 6 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tomomichi Amano | last post by:
Hello How can I delete (clear) lines that were made useing Graphics.DrawLine() ? Thanks in advance! Have a nice day!
0
by: funcSter | last post by:
I've got this bit of code: Image origImage = Image.FromFile("temp.jpg"); Image newImage = new Bitmap(objNewSize.Width, objNewSize.Height, origImage.Pixelformat); Graphics objGraphic =...
2
by: Daniel | last post by:
how come when i do oGraphics.FillEllipse it draws blury? is there anyway to adjust this default compression to not be blury when drawing a simple ellipse?
7
by: Marc Pelletier | last post by:
Hello all, I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as...
5
by: active | last post by:
In a PictureBox if I want to clear the Image or background do I simply use FromFile("") (just a guess) I did see about FromFile: If the file does not have a valid image format or if GDI+ does...
7
by: moondaddy | last post by:
I'm painting images onto a windows form using this method: e.Graphics.DrawImageUnscaled(m_ItemImage, x, y) every time I select a product. However, some products don't have an image so when a...
2
by: Tamer Abdalla via DotNetMonster.com | last post by:
Hello, everyone! I DO need some help in order to understand how to create graphics in VB.NET. I'm a little bit confused... I once knew a time when using Point & PSet was almost the only way to...
4
by: =?Utf-8?B?R3VzIENodWNo?= | last post by:
I got a simple line of code that paints on a panel. I would like to add a clear button to clear the panel but I’m not to sure how. Panel.MouseMove Dim g As Graphics =...
11
by: Slickuser | last post by:
I have this function that will fill the ellipse every 10 seconds with specific x,y,w,h. Now I want do the the reverse, to clear the ellipse with given x,y using Timer at every 30s. Or I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.