473,785 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

kspiros
16 New Member
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 2082
Plater
7,872 Recognized Expert Expert
Don't keep drawing the elipse?
Oct 31 '08 #2
tlhintoq
3,525 Recognized Expert Specialist
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 New Member
Don't keep drawing the elipse?
How can i dispose it?
Nov 1 '08 #4
kspiros
16 New Member
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 Recognized Expert Specialist
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 New Member
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 New Member
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 Recognized Expert Expert
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 New Member
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

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

Similar topics

2
20967
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
898
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 = Graphics.FromImage(newImage); objGraphic.CompositingQuality = CompositingQuality.HighQuality; objGraphic.SmoothingMode = SmoothingMode.HighQuality;
2
1632
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
8744
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 returning a bitmap instance. In my asp.net code I think I should call this method to return a bitmap and then somehow stream it using the response object to the Webcontrols.image. Is that right? The image object is on a page with a number of...
5
9108
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 not support the pixel format of the file, this method throws an OutOfMemoryException exception.
7
2055
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 user selects a different product from a list and that product doesn't have an image, I need to clear the image from the previous product that was painted onto the form. I was thinking of creating a clear image and using the DrawImageUnscaled
2
1678
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 make some interesting apps which could tranform images (i.e. making saturation of colours "heavy", or gradually fade to grayscale, or "erasing" a colour... and so on), while nowadays it seems quite impossible. Now that I got .NET over...
4
7574
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 = Me.Panel1.CreateGraphics() g.FillEllipse(New SolidBrush(Value), e.X, e.Y, SizePt, SizePt) g.Dispose() cmdClear_Click Me.Panel.?????
11
6735
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 put these (x,y,w,h) to an array? Later go back the array and fill ellipse with the same color as background? Is there an easy way?
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.