2016-03-25 6 views
0

Ich erstelle Desktop-Aufnahme (Bildschirmaufnahme) Anwendung mit DirectShow.NET und C#. Ich bin fast fertig, die Anwendung kann den Desktop-Bildschirm aufnehmen. So malen Mauszeiger in Aufnahme-Video I BufferCB von SampleGrabber und mit Hilfe meiner anderen Posten Fliped cursor icon on desktop recording using directshow ich in der Lage bin zu malen Mauszeiger in der richtigen OrientierungProblem von "Parameter ist nicht gültig" in BufferCB

Hier implementiert haben, ist mein Code von BufferCB:

[System.Security.Permissions.SecurityPermission(
System.Security.Permissions.SecurityAction.LinkDemand, Flags = 
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] 
int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) 
{ 
    if (!wait) 
    { 
     wait = true; 
     Rectangle imageBounds = new Rectangle(0, 0, m_videoWidth, m_videoHeight); 
     Bitmap bitmap = new Bitmap(m_videoWidth, m_videoHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
     System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(imageBounds, System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat); 
     IntPtr ptr = bitmapData.Scan0; 
     bitmap.UnlockBits(bitmapData); 
     CopyMemory(ptr, pBuffer, (uint)BufferLen); 
     bitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY); 
     using (Graphics g = Graphics.FromImage(bitmap)) 
     { 
      CURSORINFO cursorInfo; 
      cursorInfo.cbSize = Marshal.SizeOf(typeof(CURSORINFO)); 

      if (GetCursorInfo(out cursorInfo) && cursorInfo.flags == CURSOR_SHOWING) 
      {       
       IntPtr iconPointer = CopyIcon(cursorInfo.hCursor); 
       ICONINFO iconInfo; 
       int iconX, iconY; 
       if (GetIconInfo(iconPointer, out iconInfo)) 
       { 
        // calculate the correct position of the cursor 
        iconX = cursorInfo.ptScreenPos.x - ((int)iconInfo.xHotspot); 
        iconY = cursorInfo.ptScreenPos.y - ((int)iconInfo.yHotspot); 

        //GETTING ARGUMENTEXCEPTION AT BELOW LINE         
        IntPtr hdc = g.GetHdc(); 
        DrawIcon(hdc, iconX, iconY, cursorInfo.hCursor);         
        g.ReleaseHdc(hdc);         
       }       
      } 
      g.DrawImage(companylogo, m_videoWidth - 100 , 20); 
     } 
     bitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY); 
     bitmapData = bitmap.LockBits(imageBounds, System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat); 
     ptr = bitmapData.Scan0; 
     bitmap.UnlockBits(bitmapData);     
     CopyMemory(pBuffer, ptr, (uint)BufferLen); 
     bitmap.Dispose(); 
     wait = false; 
    } 
    return 0; 
} 

Mauszeiger bekommt Farbe auf Video, aber nach einiger Zeit der Aufnahme bekomme ich ArgumentException"Parameter is not valid." bei Codezeile IntPtr hdc = g.GetHdc();

Kann jemand mir helfen, setzen, um das zu lösen?

Stacktrace:
bei System.Drawing.Graphics.GetHdc()

+0

Speicherverlust, der zu einem Punkt führt, an dem ein anderer DC ausfällt? –

+1

Siehe [this] (http://stackoverflow.com/questions/3818440/parameter-is-not-valid-thrown-from-system-drawing-graphics-gethdc-only-on) Frage. –

+0

@RomanR. Warum Speicherleck passiert, wie ich mit Block, der kümmert sich um Entsorgung von Graphics-Objekt verwenden wird. – Amogh

Antwort

1

Schauen Sie sich die Antwort in this Frage. Sie diskutieren die gleiche Fehlermeldung.

Verwandte Themen