Click here to Skip to main content
15,881,248 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error: "No exports were found that match the constraint" Pin
Pete O'Hanlon5-Feb-20 8:43
mvePete O'Hanlon5-Feb-20 8:43 
AnswerRe: Error: "No exports were found that match the constraint" Pin
Richard Deeming5-Feb-20 6:44
mveRichard Deeming5-Feb-20 6:44 
QuestionHow do i get value from string textBox in C# Pin
SSI132-Feb-20 15:12
SSI132-Feb-20 15:12 
AnswerRe: How do i get value from string textBox in C# Pin
Atlaskor2-Feb-20 17:11
Atlaskor2-Feb-20 17:11 
GeneralRe: How do i get value from string textBox in C# Pin
Charmain Bush26-Feb-20 20:06
Charmain Bush26-Feb-20 20:06 
AnswerRe: How do i get value from string textBox in C# Pin
OriginalGriff2-Feb-20 19:35
mveOriginalGriff2-Feb-20 19:35 
AnswerRe: How do i get value from string textBox in C# Pin
Gerry Schmitz3-Feb-20 4:19
mveGerry Schmitz3-Feb-20 4:19 
QuestionSearching for a bitmap on my screen Pin
Atlaskor2-Feb-20 13:35
Atlaskor2-Feb-20 13:35 
Hi all, I'm currently working on a side project. I need to click on locations on the screen where an image has been found. I have gotten the code to work but its not as reliable as i would like. I successfully got the project running, and working, but as I stated before its just not reliable. The cameras location has to be EXACTLY in the same space for the bitmaps to line up. I've got some code that ill share below that I am using to find the bitmap, but I have no idea if I've done this efficiently. I'm doing all the work in Visual Studio, as that's what I've used since college. Here is the code I've thrown together for the bitmap search.

/// <summary>
        /// Find the location of a bitmap within another bitmap
        /// </summary>
        /// <param name="bmpNeedle">Image you want to find</param>
        /// <param name="bmpHaystack">Where we want to search for the image</param>
        /// <param name="location">Where we found the image</param>
        /// <returns>if the needle was found sucessfully</returns>
        private bool FindBitmap(Bitmap bmpNeedle, Bitmap bmpHaystack, out Point location, out Point locationA)
        {
            Random rnd = new Random();
            int rndmousex = rnd.Next(-5, 5);
            int rndmousey = rnd.Next(-5, 5);
            for (int outerX = 0; outerX < bmpHaystack.Width - bmpNeedle.Width; outerX++)
            {
                for (int outerY = 0; outerY < bmpHaystack.Height - bmpNeedle.Height; outerY++)
                {
                    for (int innerX = 0; innerX < bmpNeedle.Width; innerX++)
                    {
                        for (int innerY = 0; innerY < bmpNeedle.Height; innerY++)
                        {
                            Color cNeedle = bmpNeedle.GetPixel(innerX, innerY);
                            Color cHaystack = bmpHaystack.GetPixel(innerX + outerX, innerY + outerY);
                            if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
                            {
                                goto notFound;
                            }
                        }
                    }
                    location = new Point(outerX + rndmousex, outerY + rndmousey);
                    locationA = new Point(outerX, outerY);
                    return true;
                notFound:
                    continue;
                }
            }
            location = Point.Empty;
            locationA = Point.Empty;
            return false;
        }


/// <summary>
       /// Takes a snapshot of the screen
       /// </summary>
       /// <returns>screenshot</returns>
       private Bitmap Screenshot()
       {
           Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

           //creates the graphics object to make the bitmap
           Graphics g = Graphics.FromImage(bmpScreenshot);


           g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
           return bmpScreenshot;


       }


Now I run this and say I have the bitmap of the Facebook login page have it click and login (I don't!) it will ALWAYS find it, never with any issues. Now say i go into Diablo for example how can i search for a bitmap of just a particular sword and ignore the background? I have tried to make the background of the bitmaps transparent in hopes that it would only search for the sword itself but it'll never find it. It searches for the transparency I'm guessing, or am I just not cleaning my bitmaps enough?
AnswerRe: Searching for a bitmap on my screen Pin
Eddy Vluggen3-Feb-20 2:57
professionalEddy Vluggen3-Feb-20 2:57 
GeneralRe: Searching for a bitmap on my screen Pin
Atlaskor3-Feb-20 5:08
Atlaskor3-Feb-20 5:08 
GeneralRe: Searching for a bitmap on my screen Pin
Eddy Vluggen3-Feb-20 6:26
professionalEddy Vluggen3-Feb-20 6:26 
GeneralRe: Searching for a bitmap on my screen Pin
Atlaskor3-Feb-20 8:24
Atlaskor3-Feb-20 8:24 
GeneralRe: Searching for a bitmap on my screen Pin
Eddy Vluggen3-Feb-20 9:07
professionalEddy Vluggen3-Feb-20 9:07 
GeneralRe: Searching for a bitmap on my screen Pin
Atlaskor3-Feb-20 9:11
Atlaskor3-Feb-20 9:11 
GeneralRe: Searching for a bitmap on my screen Pin
Eddy Vluggen3-Feb-20 10:25
professionalEddy Vluggen3-Feb-20 10:25 
AnswerRe: Searching for a bitmap on my screen Pin
Gerry Schmitz3-Feb-20 4:11
mveGerry Schmitz3-Feb-20 4:11 
GeneralRe: Searching for a bitmap on my screen Pin
Atlaskor3-Feb-20 5:21
Atlaskor3-Feb-20 5:21 
QuestionHow to read specific field value when using LINQ to object to fetch data Pin
Mou_kol31-Jan-20 10:05
Mou_kol31-Jan-20 10:05 
AnswerRe: How to read specific field value when using LINQ to object to fetch data Pin
ZurdoDev31-Jan-20 10:47
professionalZurdoDev31-Jan-20 10:47 
AnswerRe: How to read specific field value when using LINQ to object to fetch data Pin
Gerry Schmitz31-Jan-20 10:49
mveGerry Schmitz31-Jan-20 10:49 
AnswerRe: How to read specific field value when using LINQ to object to fetch data Pin
Eddy Vluggen31-Jan-20 11:05
professionalEddy Vluggen31-Jan-20 11:05 
QuestionHow to make a "dungeon"(kinda of a small labyrinth) using devc and matrix Pin
Member 1472865028-Jan-20 19:44
Member 1472865028-Jan-20 19:44 
AnswerRe: How to make a "dungeon"(kinda of a small labyrinth) using devc and matrix Pin
OriginalGriff28-Jan-20 20:12
mveOriginalGriff28-Jan-20 20:12 
QuestionRe: How to make a "dungeon"(kinda of a small labyrinth) using devc and matrix Pin
ZurdoDev31-Jan-20 10:48
professionalZurdoDev31-Jan-20 10:48 
QuestionFileSystemWatcher Question Pin
Kevin Marois28-Jan-20 6:07
professionalKevin Marois28-Jan-20 6:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.