C# do something based on image detection [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am making a program in C#. I want it to do something if image is detected on screen. For example let's say I am making a game bot. And my health is image on my screen filled with green color like so:
FULL HP BAR
And something took my hp to this level:
TAKEN HP BAR
If the C# detects the image with hp taken, do something ... Is this possible and how can i do it ? Thanks.

I wrote the bot for game. To detect when life become low you can scan a certain pixel color and test it with the sample value (for example you can capture pixel in the middle of your rectangle and if it is green you have more then half of life).
Also I made screenshots, cut some areas and kept them as bitmaps. In a game I loaded them, then I made screenshot every second and checked if some of these bitmaps appeared in the screenshot.
To capture the screen in C# you can use CopyFromScreen method of Graphics:
var screen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
var graphics = Graphics.FromImage(screen );
graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0, 0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);

Related

c# how to detect image color [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a picture and in my picture there are several drops of blood of different colors. I want to get the color of each drop of blood (either by color name, or by color code)
you can use this to get each Pixel Color in image
using System.Drawing;
Bitmap b = new Bitmap( "Image file Path" );
Color x = b.GetPixel( x, y );

How to change the origin in Windows Forms Bitmap? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a Bitmap object in C# Windows Forms. The origin (where axis start) in this Bitmap object is located in the top-left corner. How can I change the origin to the bottom-left corner, like in usual graphs? Thank you!
You can flip the Y coordinates in a picture box by using the code in the following answer;
flip coordinates when drawing to control
private void ScaleTransformFloat(PaintEventArgs e)
{
// Begin graphics container
GraphicsContainer containerState = e.Graphics.BeginContainer();
// Flip the Y-Axis
e.Graphics.ScaleTransform(1.0F, -1.0F);
// Translate the drawing area accordingly
e.Graphics.TranslateTransform(0.0F, -(float)Height);
// Whatever you draw now (using this graphics context) will appear as
// though (0,0) were at the bottom left corner
e.Graphics.DrawRectangle(new Pen(Color.Blue, 3), 50, 0, 100, 40);
// End graphics container
e.Graphics.EndContainer(containerState);
// Other drawing actions here...
}

Winforms multi-layer graphics [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Problem example:
I have a control do draw some geometrical shapes (I use panel).
I have drawn a line.
Now when I move cursor to one of the line tips I want that point to be "highlighted" (a solid circle drawn around it).
And when I move cursor off the point, I want the "highlighting" circle to be erased, but I do not want to redraw the line.
So, technically, I need two layers:
1-st layer to draw my line(s).
2-nd layer to draw/erase highlights.
I do not want the first layer to be redrawn every time when something is drawn/erased in the second layer.
Any suggestions?
Option 1: Nest another Panel in the bottom one. This is good for overlaying graphics including semi-transparency. (Nesting means: panel2.Parent = panel1) You can nest many layers if you want to.
Option 2: Draw into the BackgroundImage of the Panel and use drawing onto the surface for the interactivce stuff.
I noted that you 'don't want to draw the line again'. This is not what you would usually say/do/try when doing graphics. If you are serious about this go for option 2!
See here for the difference of drawing onto a control and into a Bitmap and here for another example of using option 2 to display a cross as a cursor above a Bitmap.
Btw, the two options are not mutually exclusive: You could nest Panels with BackgroundImages and draw interactive stuff on the topmost one..
#TaW pretty much answered it. I set an example:
For static drawing:
private Bitmap myStaticImage;
public Form2()
{
InitializeComponent();
this.myStaticImage = new Bitmap(200, 100);
Graphics g = Graphics.FromImage(this.myStaticImage);
g.DrawLine(Pens.Red, new Point(0, 0), new Point(200, 0));
this.panel1.BackgroundImage = this.myStaticImage;
}
For dynamic drawing:
private void panel1_Paint(object sender, PaintEventArgs e)
{
// Stuff
}
I recommend using a PictureBox or a UserControl with DoubleBuffered property set to true. Panel control is not double buffered and will flicker.

Detecting Elliptical patterns in image [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In this image there are some lines and some elliptical (circular) patterns on these lines.
I want to detect these elliptical patterns in C# using Emgu.CV and OpenCV functions. Can any body please help me where should I start and what should I do first to detect these elliptical patterns?
a very simple method that still finds most of the bubbles:
threshold the image
find contours in threshold image
filter out all contours that are too small and draw all others filled
erode that mask until the vertical lines have disappeared
count the new number of blobs/contours and dilate if you need the original size
steps look like these:
thresholded (50)
contours (all)
contours (filtered mask)
eroded mask
dilated mask and overlay
as you can see it is very simple and finds most of the bubbles. If you dont know how often you have to erode, you can detect the vertical lines with HoughLines first.

C# panel drawing on button press [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My apologies if I'm missing something simple here, but I've running in circles for some time now. In short, I'd like to update the panel graphics (panel will contain simple shapes like circles and rectangles) every time a button is pressed. The code would look something like this:
private void PanelGraphics()
{
ClearThePanel(); //empties the panel
FillThePanel(); //draws new shapes in the panel
}
The function would be then called every time a button is pressed, and I understand button_events well enough so that's not a problem. However, I have no idea how to pull off the PanelGraphics() function, and a few links about panel_paint events didn't help me much.
You can draw to the panel by creating a graphics controller to it.
Graphics g = panel.CreateGraphics();
You can then use the Graphic class's plethora of methods to draw whatever you want to the panel
g.DrawCurve(parameters);
g.DrawEllipse(parameters);
g.DrawLine(parameters);
g.DrawRectangle(parameters);
To clear the panel the easiest way is to draw a box the colour of the background to the panel
g.DrawRectangle(new Pen(panel.BackColor), new Rectangle(new Point(), panel.Size));

Categories

Resources