Maussteuerung via BMP daten



  • ich bin eher noch anfänger in C++ ich programmier grad ein programm das bmp daten per maussteuerung in Paint oder so änlich übertragen kann das programm läuft aber sehr langsam könntet ihr mir helfen die performance zu steigern wäre echt dankbar 🙂

    #include <windows.h>
    #include <cstdio>
    #include <iostream>
    using namespace std;
    
    int LoadBmp(char *szBitmap)
    {
     int w, h;
     HDC hDC, hMemDC;
     COLORREF colorref;
     HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,szBitmap,
                         IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    
      if (!hBitmap) return 1;
    
      BITMAP bmp;
    
      hDC = GetDC(NULL);
    
        hMemDC = CreateCompatibleDC(hDC);
    
      GetObject(hBitmap,sizeof(bmp),&bmp);
    
      SelectObject(hMemDC, hBitmap);
    
        w = bmp.bmWidth;
    
        h = bmp.bmHeight;
    
    for(int width = 0; width < w; width++)
    
    {
    
      for(int height = 0; height < h; height++)
    
      {
    
       colorref = GetPixel(hMemDC, width, height);
    
         if(colorref == 000)
         keybd_event(VK_LBUTTON ,0x9d,0 , 0);
         SetCursorPos(height + 49, width + 253);
    
         if(colorref == CLR_INVALID) printf("x");
    
         else
         keybd_event(VK_LBUTTON,0x9d,KEYEVENTF_KEYUP,0);
       }
    
     }
       keybd_event(VK_LBUTTON,0x9d,KEYEVENTF_KEYUP,0);
       return 0;
    }
    
    int main()
    {
        char path[20] = " ";
        cout << "eingabe: ";
        cin >> path;
        cin.get();
      int Status = LoadBmp(path);
      if(Status!=0)printf("Fehler: %i Bmp konnte nicht gefunden werden",Status);
    
      getchar();
      return 0;
    }
    


  • Gewöhne dir bitte an, deinen Code vernünftig einzurücken. So kann das ja kein Mensch lesen.

    for(int i=0;i<0;i++) {
      if(0) {
        while(0) {
          for(int j=0;j<0;) {
            //...
          }
        }
      }
    }
    

    Du solltest besser direkt auf die Bitmap-Daten zugreifen, statt GetPixel (sehr langsam) zu verwenden. Das sollte bei der von dir verwendeten Struktur über bmBits gehen, schätze ich.



  • ich würde erst lieber anfangen ein array zu erstellen das er die werte einliest bevor er mit dem zeichnen anfängt aber das problem ich will ja die array grösse erst im programm bestimmen ich hab versucht per zeiger die werte vom array in der funktion in die main() funktion zu bekommen ich kriegs aber irgendwie nicht hin

    funktion:

    int LoadBmp(char* szBitmap)
    {
            int w, h;
             HDC hDC, hMemDC;
    
            COLORREF colorref;
            HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,szBitmap,
                                       IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    
            if (!hBitmap) return 1;
    
            BITMAP bmp;
    
            hDC = GetDC(NULL);
    
            hMemDC = CreateCompatibleDC(hDC);
    
            GetObject(hBitmap,sizeof(bmp),&bmp);
    
            SelectObject(hMemDC, hBitmap);
    
            w = bmp.bmWidth;
    
            h = bmp.bmHeight;
    
            int array1[w];
            int array2[h];
    
             for(int width = 0; width < w; width++)
    
               {
    
             for(int height = 0; height < h; height++)
    
              {
    
                  colorref = GetPixel(hMemDC, width, height);
    
                  if(colorref == 000)
                     {
                          array1[width] = width;
                          array2[height] = height;
                     }
    
                 if(colorref == CLR_INVALID) printf("x");
    
                 else
                    keybd_event(VK_LBUTTON,0x9d,KEYEVENTF_KEYUP,0);
             }
    
        }
           DeleteObject(hBitmap);
           keybd_event(VK_LBUTTON,0x9d,KEYEVENTF_KEYUP,0);
           return 0;
    }
    

Anmelden zum Antworten