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 links image1 image2
my code - public void work()
-
{
-
-
Graphics xGraph;
-
-
xGraph = Graphics.FromImage(pictureBox_Map.Image);
-
-
for (int i = 0; i < 5; i++)
-
{
-
-
Thread.Sleep(draw_delay);
-
-
double a;
-
a = Math.Sqrt(Math.Pow(pointcheck[0] - X[i], 2) + Math.Pow(pointcheck[1] - Y[i], 2));
-
int d = Convert.ToInt32(a);
-
-
if (Math.Abs(d) < R[i])
-
{
-
if ((elegxos[i] == 0) && (change[i] == false))
-
{
-
-
SolidBrush Brush = new SolidBrush(Color.FromArgb(255, Red[i], Green[i], Blue[i]));
-
-
pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
-
elegxos[i] = 1;
-
this.Invalidate();
-
change[i] = true;
-
}
-
}
-
else
-
{
-
SolidBrush Brush = new SolidBrush(Color.FromArgb(50, Red[i], Green[i], Blue[i]));
-
-
pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
-
this.Invalidate();
-
change[i] = false;
-
}
-
-
}
-
xGraph.Dispose();
-
-
this.Invalidate();
-
}
10 2046
Don't keep drawing the elipse?
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 - public void work()
-
{
-
-
Graphics xGraph;
-
-
xGraph = Graphics.FromImage(pictureBox_Map.Image);
-
-
for (int i = 0; i < 5; i++)
-
{
-
-
Thread.Sleep(draw_delay);
-
-
double a;
-
a = Math.Sqrt(Math.Pow(pointcheck[0] - X[i], 2) + Math.Pow(pointcheck[1] - Y[i], 2));
-
int d = Convert.ToInt32(a);
-
-
if (Math.Abs(d) < R[i])
-
{
-
if ((elegxos[i] == 0) && (change[i] == false))
-
{
-
-
SolidBrush Brush = new SolidBrush(Color.FromArgb(255, Red[i], Green[i], Blue[i]));
-
-
pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
-
elegxos[i] = 1;
-
this.Invalidate();
-
change[i] = true;
-
}
-
}
-
else
-
{
-
SolidBrush Brush = new SolidBrush(Color.FromArgb(50, Red[i], Green[i], Blue[i]));
-
-
pictureBox_Map.CreateGraphics().FillEllipse(Brush, X[i] - R[i], Y[i] - R[i], R[i], R[i]);
-
this.Invalidate();
-
change[i] = false;
-
}
-
-
}
-
xGraph.Dispose();
-
-
this.Invalidate();
-
}
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 -
mySignalClassArray[3].SetSignalAs(ENUMERATEDSIGNAL_WIFI);
-
mySignalClassArray[3].SetCenter(50,200);// Point x, Point y
-
mySignalClassArray[3].SetRange(45);// 1 pixel = 1 map scale foot
-
mySignalClassArray[3].DrawEllipse(nSignalStregth);//Weak signal becomes more transparant
-
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.
Don't keep drawing the elipse?
How can i dispose it?
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 -
mySignalClassArray[3].SetSignalAs(ENUMERATEDSIGNAL_WIFI);
-
mySignalClassArray[3].SetCenter(50,200);// Point x, Point y
-
mySignalClassArray[3].SetRange(45);// 1 pixel = 1 map scale foot
-
mySignalClassArray[3].DrawEllipse(nSignalStregth);//Weak signal becomes more transparant
-
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
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. -
Bitmap myTempMap = null;// member variable
-
Bitmap BaseMapImage = null; // set this to your street map so you always have a clean copy of it to use later
-
MakeNewMap()
-
{
-
myTempMap = BaseMapImage;
-
UpdateWiFi();// This method will draw an ellipse for the WiFi signal
-
UpdateWiMax();// This method will draw an ellipse for the WiMax signal
-
UpdateUMTS();// you get the drift
-
-
}
-
private void timer1_Tick(object sender, System.EventArgs e)
-
{
-
MakeNewMap();
-
pictureBox_map.Image = myTempMap;
-
}
-
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. -
Bitmap myTempMap = null;// member variable
-
Bitmap BaseMapImage = null; // set this to your street map so you always have a clean copy of it to use later
-
MakeNewMap()
-
{
-
myTempMap = BaseMapImage;
-
UpdateWiFi();// This method will draw an ellipse for the WiFi signal
-
UpdateWiMax();// This method will draw an ellipse for the WiMax signal
-
UpdateUMTS();// you get the drift
-
-
}
-
private void timer1_Tick(object sender, System.EventArgs e)
-
{
-
MakeNewMap();
-
pictureBox_map.Image = myTempMap;
-
}
-
thank you these was extremely helpful!!! thanks a lot!!!
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 - 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?
The dimensions that you supply to the drawing are not the center point but the bounding rectangle, have you been formulating for that?
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 - 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?
I found the reason why these is the answer!!! - xGraph.FillEllipse(Brush, X - R, Y - R, 2 * R, 2 * R);
Thanks a lot for all your help!!!
Sign in to post your reply or Sign up for a free account.
Similar topics
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!
|
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 =...
|
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?
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |