Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 85

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
Finding program width, pixel reading
Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Finding program width, pixel reading

  1. #1

    Finding program width, pixel reading

    Hello, I worked on pixel reader for 4 days, and today I decided to trash it.
    Then I took it out of the trash and thought "Maybe someone need the position functions for screen size".
    I used a class file, so I changed "v. " in front of every variable, if error, tell me........

    INFO:
    getpixel inside of bitmap variable is used with bitmaps,
    the Pinvoke getpixel is used for different windows,
    the BitBlt is used for different windows and very fast,
    and the fastest way (that increased speed so much) was using lockbits and bitmaps

    lockbits is found at:
    http://www.codeproject.com/Tips/2404...er-with-Csharp

    and BitBlt is quite complicated, I havent got it to work.
    Here is code:

    First, what you will use (not sure if all is needed):
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Collections;
    using System.Drawing.Imaging;
    Then, pinvokes (functions from windows dll files, still not sure)
    Code:
            [DllImport("user32.dll")]
            private static extern IntPtr GetForegroundWindow();
            [DllImport("user32.dll")]
            private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
            [DllImport("user32.dll")]
            static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    Then, variables:
    Code:
                    int r = 0;
                    int g = 0;
                    int b = 0;
                    bool Hello = true;
                    IntPtr handle = IntPtr.Zero;
                    int chars = 256;
                    StringBuilder buff;
                    int chars;
                    Bitmap printScreen = new Bitmap(0, 0);
                    Graphics Screen;
                    int programWidth;
    
                    /* Screen Variables */
                    int screenStartY;
                    int screenStartX;
                    int screenstartYMin;
                    int screenstartXMin;
                    int screenStartEnd;
                    double tileSize; // Remember, use  (int)tileSize when working
                    /* END */
    And function:

    Code:
    static int FindWidth()
            {
    
                    while (Hello && GetAsyncKeyState(Keys.Escape) == 0)
                    {
                        System.Threading.Thread.Sleep(150);
                        handle = GetForegroundWindow();
                        buff = new StringBuilder(chars);
                        if (GetWindowText(handle, buff, chars) > 0)
                        {
                            if (buff.ToString() == "Tibia")
                            {
                                printScreen = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height);
                                Screen = Graphics.FromImage(printScreen as Image);
                                Screen.CopyFromScreen(0, 0, 0, 0, printScreen.Size);
                                
                                for (int i = Screen.PrimaryScreen.WorkingArea.Width - 1; i > Screen.PrimaryScreen.WorkingArea.Width / 2; i--)
                                {
                                    r = printScreen.GetPixel(i, (Screen.PrimaryScreen.WorkingArea.Height) - 10).R;
                                    g = printScreen.GetPixel(i, (Screen.PrimaryScreen.WorkingArea.Height) - 10).G;
                                    b = printScreen.GetPixel(i, (Screen.PrimaryScreen.WorkingArea.Height) - 10).B;
    
                                    if (r > 110 && r < 180 &&
                                        g > 110 && g < 180 &&
                                        b > 110 && b < 180)
                                    {
                                        programWidth = i;
                                        for (int c = 0; c < Screen.PrimaryScreen.WorkingArea.Height/3; c++)
                                        {
                                            r = printScreen.GetPixel((int)(Screen.PrimaryScreen.WorkingArea.Width/2), c).R;
                                            g = printScreen.GetPixel((int)(Screen.PrimaryScreen.WorkingArea.Width / 2), c).G;
                                            b = printScreen.GetPixel((int)(Screen.PrimaryScreen.WorkingArea.Width / 2), c).B;
    
                                            if (r > 36 && r < 50 && g > 36 && g < 50 && b > 36 && b < 50)
                                            {
                                                screenStartY = c + 1;
                                                break;
                                            }
                                        }
    
                                        for (int k = programWidth-2; k > (Screen.PrimaryScreen.WorkingArea.Width/2); k--)
                                        {
                                            r = printScreen.GetPixel(k, (Screen.PrimaryScreen.WorkingArea.Height/2)).R;
                                            g = printScreen.GetPixel(k, (Screen.PrimaryScreen.WorkingArea.Height/2)).G;
                                            b = printScreen.GetPixel(k, (Screen.PrimaryScreen.WorkingArea.Height/2)).B;
                                            if (r > 110 && r < 130 && g > 110 && g < 130 && b > 110 && b < 130)
                                            {
                                                screenStartX = k - 2;
                                                break;
                                            }
                                        }
    
                                        for (int l = 0; l < Screen.PrimaryScreen.WorkingArea.Width/3; l++)
                                        {
                                            r = printScreen.GetPixel(l, v.screenStartY).R;
                                            g = printScreen.GetPixel(l, v.screenStartY).G;
                                            b = printScreen.GetPixel(l, v.screenStartY).B;
                                            if (r <= 50 && g <= 50 && b <= 50)
                                            {
                                                screenstartXMin = l + 1;
                                                break;
                                            }
                                        }
    
    
                                        screenStartEnd = (screenStartX - screenstartXMin);
                                        tileSize = (screenStartEnd / 15);
    
                                        return i;
                                    }
                                }
                            }
                        }
                    }
                    return 100;
            }
    Remember, you need:

    Code:
                this.FormBorderStyle = FormBorderStyle.None;
                this.TopMost = true;
                this.Width = (Screen.PrimaryScreen.WorkingArea.Width - FindWidth());
                this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
    inside of public FormName() {}

    This program will only start when Tibia is started and logged in.
    If this program continues in an endless while loop, press ESCAPE.

    thxbb
    Last edited by Xleniz; 01-27-2013 at 04:06 PM.

  2. #2
    Senior Member
    Join Date
    Nov 2010
    Posts
    397
    This code is so so so so long..............

    http://tpforums.org/vbulletin/showth...ding-By-Wesker

    Lockbits is overrated and its pure BS, also why does every1 use BitBlt ? if u wait a few days until i finish my tutorial you will be able to do magic with the piece of API ill give there, of course you will have to translate it to your lenguage

  3. #3
    Quote Originally Posted by Wesker View Post
    This code is so so so so long..............

    http://tpforums.org/vbulletin/showth...ding-By-Wesker

    Lockbits is overrated and its pure BS, also why does every1 use BitBlt ? if u wait a few days until i finish my tutorial you will be able to do magic with the piece of API ill give there, of course you will have to translate it to your lenguage
    mkay, im just saying lockbits loads 100+ pixel position colors under 0.2 sec, while bitmap.getpixel takes 8+ seconds...
    u know better way?

  4. #4
    Senior Member
    Join Date
    Nov 2010
    Posts
    397
    Quote Originally Posted by Xleniz View Post
    mkay, im just saying lockbits loads 100+ pixel position colors under 0.2 sec, while bitmap.getpixel takes 8+ seconds...
    u know better way?
    if you read about lockbits, the things you can actually do with it are limited, and doesn't do the job well, theres alot of stuff around lockbits, and i forgot the other1 on gui mmm but ill remember it eventually
    the easier and faster way should be around the API but getting it from the x,y

    Code:
    Dim tmpOleColor As Integer = API_Calls.GetPixel(ScreenDC, xIndex, ypos)
    this way your not calling a bitmap and your not performing an stupid task around getpixel and making it slower, but then again thats my point of view on it

    sorry playing league of legends cant type much about it LOL

    so i was on this matter and it reminds me pixels can be read by percentages, there's no need to read a hole line, only if you want the exact amount of pixels, and yet if you do it like that it will be problematic in a bot, should people heal by the number of pixels that can be 1-500 and how do they know how much help is that ? or should they just count how many pixels to x, x+150 = health x+75 = heals and so on there several options on what your task should be in your case

    Code:
     Screen = Graphics.FromImage(printScreen as Image);
    Your printing screens with is highly unrecommended, and slows the performance of the bot, and you're also doing a bitmap task

    Code:
     PrintScreen = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height);
    So my question is is it really .2 secs when you're reading the wide on the screen ?
    Have you confirm that the infinite loop doesn't spill bugs such as "clipboard errors" , " IDATA object" ? Besides that you're using windows.forms i would avoid that at all cost

    have u consider working with the API ? mmm im not nearly familiar with csharp i dont know if u have to invoke Gdi32 but your using user32 so ill guess you have to


    Code:
    <DllImport("Gdi32.dll")>
    however this contains http://msdn.microsoft.com/en-us/library/ms927613.aspx

    StretchDIBits This function copies the color data for a rectangle of pixels in a DIB to the specified destination rectangle.

    SetPixel This function sets the pixel at the specified coordinates to the specified color.

    RoundRect This function draws a rectangle with rounded corners.

    GetPixel This function retrieves the RGB color value of the pixel at the specified coordinates.

    GetNearestColor This function returns the system palette color that will be displayed when the specified color value is used.

    GetDC This function retrieves a handle to a display device context for the client area of the specified window.

    GetCurrentPositionEx This function retrieves the current position in logical coordinates.

    DeleteDC This function deletes the specified DC.
    BitBlt This function transfers pixels from a specified source rectangle to a specified destination rectangle, altering the pixels according to the selected raster operation (ROP) code.

    IF YOUR USING BitBlt your going to use extra steps, is better to just call getpixel, but not from the clipboard or bitmap but from the screen, it will be faster and it wont bug when you open/close windows like i believe it occurs with your code "rare" times, it happend with the book pages i posted the code was a bit buggy

  5. #5
    Super Moderator
    Join Date
    May 2007
    Posts
    1,191
    You know you can use the Windows API to accomplish the same task with more accuracy, right?

  6. #6
    Quote Originally Posted by Wesker View Post
    if you read about lockbits, the things you can actually do with it are limited, and doesn't do the job well, theres alot of stuff around lockbits, and i forgot the other1 on gui mmm but ill remember it eventually
    the easier and faster way should be around the API but getting it from the x,y

    Code:
    Dim tmpOleColor As Integer = API_Calls.GetPixel(ScreenDC, xIndex, ypos)
    this way your not calling a bitmap and your not performing an stupid task around getpixel and making it slower, but then again thats my point of view on it

    sorry playing league of legends cant type much about it LOL

    so i was on this matter and it reminds me pixels can be read by percentages, there's no need to read a hole line, only if you want the exact amount of pixels, and yet if you do it like that it will be problematic in a bot, should people heal by the number of pixels that can be 1-500 and how do they know how much help is that ? or should they just count how many pixels to x, x+150 = health x+75 = heals and so on there several options on what your task should be in your case

    Code:
     Screen = Graphics.FromImage(printScreen as Image);
    Your printing screens with is highly unrecommended, and slows the performance of the bot, and you're also doing a bitmap task

    Code:
     PrintScreen = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height);
    So my question is is it really .2 secs when you're reading the wide on the screen ?
    Have you confirm that the infinite loop doesn't spill bugs such as "clipboard errors" , " IDATA object" ? Besides that you're using windows.forms i would avoid that at all cost

    have u consider working with the API ? mmm im not nearly familiar with csharp i dont know if u have to invoke Gdi32 but your using user32 so ill guess you have to


    Code:
    <DllImport("Gdi32.dll")>
    however this contains http://msdn.microsoft.com/en-us/library/ms927613.aspx



    BitBlt This function transfers pixels from a specified source rectangle to a specified destination rectangle, altering the pixels according to the selected raster operation (ROP) code.

    IF YOUR USING BitBlt your going to use extra steps, is better to just call getpixel, but not from the clipboard or bitmap but from the screen, it will be faster and it wont bug when you open/close windows like i believe it occurs with your code "rare" times, it happend with the book pages i posted the code was a bit buggy
    Yes I know bitmap loading is not good, which is why I aimed on bitblt..
    Saving an image takes for me under 0.1 second (less?), I dont see problem,
    and I have a distant memory of me using getpixel pinvoke from HDC taking 10+ seconds.

    Btw, is getpixel pinvoke same as yours?:{

  7. #7
    Senior Member
    Join Date
    Nov 2010
    Posts
    397
    Quote Originally Posted by Xleniz View Post
    Yes I know bitmap loading is not good, which is why I aimed on bitblt..
    Saving an image takes for me under 0.1 second (less?), I dont see problem,
    and I have a distant memory of me using getpixel pinvoke from HDC taking 10+ seconds.

    Btw, is getpixel pinvoke same as yours?:{
    might not be i dont know where ur getting getpixel, since ur not using the dll, your probably just using csharp getpixel, no idea to be honest but ill paste my code i guess in the afternoon

  8. #8
    Quote Originally Posted by Wesker View Post
    might not be i dont know where ur getting getpixel, since ur not using the dll, your probably just using csharp getpixel, no idea to be honest but ill paste my code i guess in the afternoon
    Well, I used pinvoke (Pinvoke = load dlls with interop from pinvoke.net in C#),
    so it is the same. I think DLL is slow, and lockbits are fast but have to load multiple images.

    kkkkkkkkkk.

    Keep positive.
    kkkkkkkkk.

  9. #9
    Quote Originally Posted by Wesker View Post
    Lockbits is overrated and its pure BS, also why does every1 use BitBlt ? if u wait a few days until i finish my tutorial you will be able to do magic with the piece of API ill give there, of course you will have to translate it to your lenguage

    LockBits() is the accepted standard for any commercial software that works intensively with images. Internally, GetPixel() and SetPixel() both have to call LockBits() everytime they are used - this means LockBits() IS able to to everything they are able to do, if used correctly. Also, due to the fact that you only have to call it once for all pixels, it is much faster. I think it was Jo3Bingham who had a sprite ripper that gained like 2000% efficiency when he switched from GetPixel() to LockBits() (Could be wrong on the details, it's been a while).

    It's really annoying/pathetic how you try to find a reason to relentlessly criticize everything you see. At least try and use reasonable arguments.

  10. #10
    Administrator
    Join Date
    Mar 2007
    Posts
    1,723
    Quote Originally Posted by DarkstaR View Post
    LockBits() is the accepted standard for any commercial software that works intensively with images. Internally, GetPixel() and SetPixel() both have to call LockBits() everytime they are used - this means LockBits() IS able to to everything they are able to do, if used correctly. Also, due to the fact that you only have to call it once for all pixels, it is much faster. I think it was Jo3Bingham who had a sprite ripper that gained like 2000% efficiency when he switched from GetPixel() to LockBits() (Could be wrong on the details, it's been a while).

    It's really annoying/pathetic how you try to find a reason to relentlessly criticize everything you see. At least try and use reasonable arguments.
    This is correct. Sketchy is the one who introduced me to LockBits()/UnlockBits() and I will never use GetPixel()/SetPixel() again. Also, now that I use WPF, instead of WinForms, it uses DirectX instead of GDI so you can't use LockBits() (unless you reference it), but using BitmapResource is probably twice as fast as LockBits(), and that's saying something.
    Last edited by jo3bingham; 01-29-2013 at 07:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •