StrataFrame Forum

CaptureScreenToFile - Error

http://forum.strataframe.net/Topic19567.aspx

By Rogerio Mauri - 9/20/2008

Method returns GDI error.

  - Windows Vista
  - VS2005
  - fileName = "C:\\Temp\\Tela.jgp"



// Método para salvar screen em arquivo
private void CapturaScreen(string fileName)
{
     MicroFour.StrataFrame.Tools.
ScreenCapture.CaptureScreenToFile(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}

System.Runtime.InteropServices.ExternalException was unhandled by user code
  Message="Erro genérico de GDI+."
  Source="System.Drawing"
  ErrorCode=-2147467259
  StackTrace:
       em System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
       em System.Drawing.Image.Save(String filename, ImageFormat format)
       em MicroFour.StrataFrame.Tools.ScreenCapture.CaptureScreenToFile(String FileName, ImageFormat Format)
       em NCClube.Forms.FormCracha.cmdFoto_Click(Object sender, EventArgs e) na C:\Users\Rogerio\Documents\Visual Studio 2005\Projects\StrataFrameProjects\NCClube\NCClube\Forms\FormCracha.cs:linha 111
       em System.Windows.Forms.Control.OnClick(EventArgs e)
       em System.Windows.Forms.Button.OnClick(EventArgs e)
       em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       em System.Windows.Forms.Control.WndProc(Message& m)
       em System.Windows.Forms.ButtonBase.WndProc(Message& m)
       em System.Windows.Forms.Button.WndProc(Message& m)
       em System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
       em System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
       em System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

By Rogerio Mauri - 9/20/2008

Rogerio Mauri (09/20/2008)

  - fileName = "C:\\Temp\\Tela.jgp"

- fileName = "C:\\Temp\\Tela.jpg"

By Ivan George Borges - 9/20/2008

Hey Rogério.

No idea about what can be wrong... Tongue

Just a thought, but have you tried isolating the problem... maybe hardcoding the fileName, like "C:\". Also, trying a different format, .Bmp maybe.

Also, you could try the formats on this post:

http://forum.strataframe.net/FindPost13029.aspx

Also, Google gdi ErrorCode=-2147467259 , there are some solutions over there, might be a threading thing.

By Rogerio Mauri - 10/1/2008

Ivan... Boa Noite...

Dê uma olha neste tópico do forum MSDN. Acho que será necessário um ajuste nesse recurso.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2459309&SiteID=1

By Rogerio Mauri - 10/8/2008

??? Crying
By Rogerio Mauri - 10/19/2008

???
By Trent L. Taylor - 10/20/2008

I know that you want an answer here, but this is an issue with your API in your environment.  We use the Windows API to capture the screen, so if you have an issue on your Windows installation or environment, then it could present this type of error.

I am running Windows Vista as well and have tested this on several machines without issue.  You can see the attached screenshot that was created when I clicked the Button2 button on the form in the image.  But here are some things to check:

  1. You are trying to use the CaptureImageToFile.  But do you have sufficient permissions to write to the specified folder location?
  2. You may want to CaptureScreen method which returns an Image object.  You can then store that image in a database or whatever you like.  This is always good when you want to keep track of error logs or may have permission issues on a machine.