Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 12:35

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# Bitmap Screen um Cursor | CopyFromScreen

Discussion on C# Bitmap Screen um Cursor | CopyFromScreen within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1

 
Bonnyfication's Avatar
 
elite*gold: 157
Join Date: Oct 2010
Posts: 855
Received Thanks: 331
C# Bitmap Screen um Cursor | CopyFromScreen

Servus,
Also folgender Stand:

Ich habe eine Anwendung, die einen Screenshot erstellt und diesen dann auswertet und die Koordinaten eines bestimmten Farbwertes sucht.

Da er allerdings der Kompletten screen durchsucht wird dauert das ganze zu lange.

Ich möchte gerne nur einen Bereich um die aktuelle Mausposition durchsuchen.
Mit Bitmap etc habe ich noch nicht so viel gearbeitet und ich weis nicht wirklich, wie ich das ganze dann angebe.

Anbei der Code:

Screen vom Bildschirm
Code:
        private Bitmap CaptureScreen()
        {
            //Point a = new Point();
            //a = Control.MousePosition;


            Bitmap b = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            using (Graphics g = Graphics.FromImage(b))
            {
                g.CopyFromScreen(new Point(0, 0), new Point(0, 0), b.Size);
            }

            return b;
        }
Suchprozess nach dem Pixel

Code:
        public Point GetPixelPosition(Color SearchColor, bool IgnoreAlphaChannel)
        {
            //Point a = new Point();
            //a = Control.MousePosition;


            _ColorFound = false;
            Point PixelPt = new Point(0, 0);

            using (Bitmap b = CaptureScreen())
            {
                for (int i = 0; i < b.Width; i++)
                {
                    if (this._ColorFound)
                        break;

                    for (int j = 0; j < b.Height; j++)
                    {
                        if (this._ColorFound)
                            break;

                        Color tmpPixelColor = b.GetPixel(i, j);
                        if (((tmpPixelColor.A == SearchColor.A) || IgnoreAlphaChannel)
                            && (tmpPixelColor.R == SearchColor.R)
                            && (tmpPixelColor.G == SearchColor.G)
                            && (tmpPixelColor.B == SearchColor.B)
                            )
                        {
                            PixelPt.X = i;
                            PixelPt.Y = j;
                            this._ColorFound = true;
                        }
                    }
                }
            }

            return PixelPt;
        }

hat jemand eine Idee?

Mfg OddN3ss


#SOLVED°!

Code:
public Point GetPixelPosition(Color SearchColor, bool IgnoreAlphaChannel, int pixelsToSearchAround)
    {
        Point mousePosition = Cursor.Position;

        _ColorFound = false;
        Point PixelPt = new Point(0, 0);

        using (Bitmap b = CaptureScreen())
        {
            int minX = mousePosition.X - pixelsToSearchAround;
            int maxX = mousePosition.X + pixelsToSearchAround;
            int minY = mousePosition.Y - pixelsToSearchAround;
            int maxY = mousePosition.Y + pixelsToSearchAround;
            if(minX < 0) minX = 0;
            if(minY < 0) minY = 0;
            if(maxX > b.Width) maxX = b.Width;
            if(maxY > b.Height) maxY = b.Height;

            for (int i = minX; i < maxX; i++)
            {
                if (this._ColorFound)
                    break;

                for (int j = minY; j < maxY; j++)
                {
                    if (this._ColorFound)
                        break;

                    Color tmpPixelColor = b.GetPixel(i, j);
                    if (((tmpPixelColor.A == SearchColor.A) || IgnoreAlphaChannel)
                        && (tmpPixelColor.R == SearchColor.R)
                        && (tmpPixelColor.G == SearchColor.G)
                        && (tmpPixelColor.B == SearchColor.B)
                        )
                    {
                        PixelPt.X = i;
                        PixelPt.Y = j;
                        this._ColorFound = true;
                    }
                }
            }
        }

        return PixelPt;
    }
Bonnyfication is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
Bitmap
07/19/2014 - Seafight - 3 Replies
hi all if somebody can import bitmap in shipwreck bot, please help us, so in every thread you say that we should help for everyone and to play together so when i ask something everyone shut up and don`t answer my question ?! that`s one game, help for insert this bitmap, cause my penelope bot don`t work. Thank you
Bitmap suchen
04/22/2014 - .NET Languages - 6 Replies
Wie kann ich eine Bitmap auf dem Desktop suchen? Sodass es zum Beispiel: Das Icon von Google Chrome suchen und drauf drückt. Danke schon mal.
Failed to update Bitmap ....
07/13/2013 - Technical Support - 4 Replies
Hallo Com, ich habe seit einigen Tagen ein Problem beim Start meines Win7 Laptops. Wenn ich starte, läuft alles gut, aber sobald ich kurz vor dem Desktop bin. Sprich, beim Login Fenster, ist der Bildschirm schwarz und ein Fenster mit dem Titel expstart.exe und drin steht: Failed to update Bitmap (eine Zahl) :24 So in der Art. Wenn ich OK drücke, kommt das noch ein paar Mal und dann bin ich auch auf dem Desktop. Falls es hilft. Ich habe kein Passwort und bin der einzige Benutzer.
Tiles to one bitmap, screws up x_X
08/23/2012 - CO2 Programming - 3 Replies
So I'm trying to combine tiles into a single bitmap. This is how I'm doing it: Bitmap bit = new Bitmap(mapWidth, mapHeight); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bit)) { for (int y = 0; y < mapHeight; y += 32) {
Cursor Disappears | Cursor verschwindet
06/23/2012 - League of Legends - 2 Replies
Ja, wie in dem Titel schon gesagt: In League of Legends verschwindet manchmal plötzlich mein Cursor. ich sehe dann 1. nicht mehr wohin ich klicke (außer ich drücke "X", "V" oder "G" weil da dann entweder grüne oder rote striche sind wo der cursor ist ) und 2. muss ich meinen rechner neustarten, weil danach, wenn ich LoL beende mein Mauszeiger fehlt. Weis irgendjemand was es damit aufsich hat? Es ist auch nicht jedes Spiel, aber wenn es dazu kommt Nervt es <.< Danke im Vorraus :) MFG



All times are GMT +2. The time now is 12:35.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.