I created a program that takes a picture of the current form. When the button clicks it takes a screenshot, attaches to an email, then sends. It worked the first click then on second click I get the following error. I was completed with this part of the program for a while when all the sudden it stopped working, not sure why. Just brought to my attention that it stopped today.
Error:
<pre>See the end of this message for details on invoking <br />
just-in-time (JIT) debugging instead of this dialog box.<br />
<br />
************** Exception Text **************<br />
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.<br />
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)<br />
at System.Drawing.Image.Save(String filename, ImageFormat format)<br />
at Townsend_Leather_Desktop_App.tm_idr_form.Button4_Click(Object sender, EventArgs e)<br />
at System.Windows.Forms.Control.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)<br />
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br />
at System.Windows.Forms.Control.WndProc(Message& m)<br />
at System.Windows.Forms.ButtonBase.WndProc(Message& m)<br />
at System.Windows.Forms.Button.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br />
<br />
<br />
************** Loaded Assemblies **************<br />
mscorlib<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3468.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
Townsend Leather Desktop App<br />
Assembly Version: 1.0.0.0<br />
Win32 Version: 1.0.0.0<br />
CodeBase: file:----------------------------------------<br />
Microsoft.VisualBasic<br />
Assembly Version: 10.0.0.0<br />
Win32 Version: 14.7.3190.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3451.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Core<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3468.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Windows.Forms<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3324.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Drawing<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Configuration<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3324.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Xml<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Runtime.Remoting<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Data<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3260.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Transactions<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3260.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.EnterpriseServices<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
System.Runtime.Caching<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3190.0<br />
CodeBase: file:----------------------------------------<br />
Accessibility<br />
Assembly Version: 4.0.0.0<br />
Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
CodeBase: file:----------------------------------------<br />
<br />
************** JIT Debugging **************<br />
To enable just-in-time (JIT) debugging, the .config file for this<br />
application or computer (machine.config) must have the<br />
jitDebugging value set in the system.windows.forms section.<br />
The application must also be compiled with debugging<br />
enabled.<br />
<br />
For example:<br />
<br />
<configuration><br />
<system.windows.forms jitDebugging="true" /><br />
</configuration><br />
<br />
When JIT debugging is enabled, any unhandled exception<br />
will be sent to the JIT debugger registered on the computer<br />
rather than be handled by this dialog box.<br />
</pre>
I have the following function:
Private Function GetFormImage(ByVal include_borders As Boolean) As Bitmap
Dim wid As Integer = Me.Width
Dim hgt As Integer = Me.Height
Dim bm As New Bitmap(wid, hgt)
Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
wid = Me.ClientSize.Width
hgt = Me.ClientSize.Height
Dim bm2 As New Bitmap(wid, hgt)
Dim pt As New Point(0, 0)
pt = PointToScreen(pt)
Dim dx As Integer = pt.X - Me.Left
Dim dy As Integer = pt.Y - Me.Top
Dim gr As Graphics = Graphics.FromImage(bm2)
gr.DrawImage(bm, 0, 0, New Rectangle(dx, dy, wid, hgt), GraphicsUnit.Pixel)
Return bm
End Function
Here is the call of the function:
GetFormImage(True).Save("F:\TLS\TLC\system_temp\ticketmaker_email.jpg", ImageFormat.Jpeg)
What I have tried:
Looked around most said the error was related to file permissions. I know its not perms as it works once fine. Was working before perfectly also.
I saw that there was something about memory stream but not sure how I would pass that.
Any feedback is greatly appreciated!