Autor Beitrag
Spectus.gn
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 38

Win XP
C# (VS 2008 Pro)
BeitragVerfasst: So 18.01.09 22:40 
Servus.
Ich habe ein Problem. Und zwar kann ich laut dem Quelltext unten ca. 30 Screenshots in der Sekunde machen. Das habe ich in einem Extraprogramm gestestet. aber wenn ich das dann in mein Programm einglieder, sind es auf einmal nur noch ca. 5. Fangt mir bitte nicht mit CopyFromScreen an, dass ist nämlich nur halb so schnell. Ich weiß einfach nichtmehr, wo da der Fehler liegt. Der Taskmanager sagt auch, dass das Programm das ganze System auslastet, darf es zwar auch, aber es braucht ebenso den ganzen RAM... Ich bin ratlos.

Das ist der Quelltext, mit den ca. 5 Screenshots/sek.
Hier "wartet" das Programm, bis an den Stellen
int vX = Marker.X - 74;
int vY1 = Marker.Y + Convert.ToInt32(textBox2.Text)
int vY2 = Marker.Y + Convert.ToInt32(textBox3.Text)

Color UpperPixel = lBitmap.GetPixel(vX, vY1);
Color LowerPixel = lBitmap.GetPixel(vX, vY2);

die Farbe weiß wird. Verpasst aber meistens den Moment, da er ja nur 5 Screens/Sek schafft.
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
            Point Marker = new Point(get1 - 2, get2 - 2);


            Bitmap lBitmap = new Bitmap(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height);
            IntPtr hWnd = GetDesktopWindow();
            IntPtr hSourceDC = GetWindowDC(hWnd);
            IntPtr hDestDC = CreateCompatibleDC(hSourceDC);
            IntPtr hBitmap = CreateCompatibleBitmap(hSourceDC, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height);
            IntPtr hObject = SelectObject(hDestDC, hBitmap);
            BitBlt(hDestDC, 00, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height, hSourceDC, 00, SRCCOPY);
            lBitmap = Image.FromHbitmap(hBitmap);

            int vX = Marker.X - 74;
            int vY1 = Marker.Y + Convert.ToInt32(textBox2.Text);
            int vY2 = Marker.Y + Convert.ToInt32(textBox3.Text);
            Color UpperPixel = lBitmap.GetPixel(vX, vY1);
            Color LowerPixel = lBitmap.GetPixel(vX, vY2);




            while (!((UpperPixel == LowerPixel) && (UpperPixel == Color.FromArgb(255255255255))))
            {
    
                hObject = SelectObject(hDestDC, hBitmap);
                BitBlt(hDestDC, 00, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height, hSourceDC, 00, SRCCOPY);
                lBitmap = Image.FromHbitmap(hBitmap);

                UpperPixel = lBitmap.GetPixel(vX, vY1);
                LowerPixel = lBitmap.GetPixel(vX, vY2);
            }


Und das ist des Programm mit den ca. 30 Screenshots/Sek. Der Background des Forms ist beim start immer schwarz und wird nach 1Sek auf weiß geändert. In der Zeit soll er immer das Form auf seine Farbe prüfen (hier geprüft via GetPixel). Da es sich nach einer Sekunde ändert hört es dann natürlich auf. Warum auch immer sind es hier auf einmal 30 Screens/Sek.
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
        private void button1_Click(object sender, EventArgs e)
        {
            Form1.ActiveForm.BackColor = Color.FromArgb(255000);
            Application.DoEvents();
            hWnd = GetDesktopWindow();
            Bitmap lBitmap = CreateScreenshot(hWnd);
            vi = 0;
            Thread s = new Thread(Thread1);
            s.Start();
            Thread.Sleep(1000);
            Form1.ActiveForm.BackColor = Color.FromArgb(255254255255);
            Application.DoEvents();
            s.Join();
        }
        private void Thread1()
        {
            lBitmap = new Bitmap(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height);
            IntPtr hWnd = GetDesktopWindow();
            IntPtr hSourceDC = GetWindowDC(hWnd);
            IntPtr hDestDC = CreateCompatibleDC(hSourceDC);
            IntPtr hBitmap = CreateCompatibleBitmap(hSourceDC, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height);
            IntPtr hObject = SelectObject(hDestDC, hBitmap);
            BitBlt(hDestDC, 00, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height, hSourceDC, 00, SRCCOPY);
            lBitmap = Image.FromHbitmap(hBitmap);

            while (!((lBitmap.GetPixel(640400) == lBitmap.GetPixel(640401))&&(lBitmap.GetPixel(640400) == Color.FromArgb(255254255255))))
            {
                hObject = SelectObject(hDestDC, hBitmap);
                BitBlt(hDestDC, 00, SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height, hSourceDC, 00, SRCCOPY);
                lBitmap = Image.FromHbitmap(hBitmap);
                vi++;
            }
        }



das sind die externen DLL-Inputs
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
        private const int SRCCOPY = 0x00CC0020;
        [DllImport("gdi32.dll")]
        private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
        [DllImport("user32.dll")]
        private static extern IntPtr GetDesktopWindow();
        [DllImport("gdi32.dll")]
        private static extern bool BitBlt(IntPtr hObject, int nXDest, int
        nYDest, int nWidth, int nHeight, IntPtr hObjectSource, int nXSrc, int
        nYSrc, int dwRop);
        [DllImport("gdi32.dll")]
        private static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int
        nWidth, int nHeight);
        [DllImport("gdi32.dll")]
        private static extern IntPtr CreateCompatibleDC(IntPtr hDC);

Bitte fragt nicht, ob alle Variablen richtig definiert sind. Das da oben ist nur ein kleiner, aber sehr wichtiger Auschnitt


Danke schonmal im Vorraus

Spectus.gn