Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll<br />
----------------------------------------<br />
Townsend Leather Desktop App<br />
    Assembly Version: 1.0.0.0<br />
    Win32 Version: 1.0.0.0<br />
    CodeBase: file:///C:/Users/codyo/AppData/Local/Apps/2.0/TJZ347LK.E64/6VQ2W5WQ.HVA/town..tion_cde9587b7f80b9c0_0001.0000_87a7cfb874c5e9d1/Townsend%20Leather%20Desktop%20App.exe<br />
----------------------------------------<br />
Microsoft.VisualBasic<br />
    Assembly Version: 10.0.0.0<br />
    Win32 Version: 14.7.3190.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll<br />
----------------------------------------<br />
System<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3451.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll<br />
----------------------------------------<br />
System.Core<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3468.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll<br />
----------------------------------------<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:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll<br />
----------------------------------------<br />
System.Drawing<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll<br />
----------------------------------------<br />
System.Configuration<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3324.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll<br />
----------------------------------------<br />
System.Xml<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll<br />
----------------------------------------<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:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll<br />
----------------------------------------<br />
System.Data<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3260.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll<br />
----------------------------------------<br />
System.Transactions<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3260.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll<br />
----------------------------------------<br />
System.EnterpriseServices<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll<br />
----------------------------------------<br />
System.Runtime.Caching<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3190.0<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Caching/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Runtime.Caching.dll<br />
----------------------------------------<br />
Accessibility<br />
    Assembly Version: 4.0.0.0<br />
    Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C<br />
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll<br />
----------------------------------------<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:
VB
Private Function GetFormImage(ByVal include_borders As Boolean) As Bitmap
    ' Make the bitmap.
    Dim wid As Integer = Me.Width
    Dim hgt As Integer = Me.Height
    Dim bm As New Bitmap(wid, hgt)
    ' Draw the form onto the bitmap.
    Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
    ' Make a smaller bitmap without borders.
    wid = Me.ClientSize.Width
    hgt = Me.ClientSize.Height
    Dim bm2 As New Bitmap(wid, hgt)
    ' Get the offset from the window's corner to its client
    ' area's corner.
    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
    ' Copy the part of the original bitmap that we want
    ' into the bitmap.
    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:
VB
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!
Posted
Updated 25-Nov-19 5:03am
Comments
Dave Kreskowiak 25-Nov-19 12:35pm    
Did you load that image file somewhere else in the code? What does that code look like?
Richard Deeming 27-Nov-19 14:11pm    
Not a solution to your error, but are you sure you're returning the correct Bitmap object? I can't see any point in creating and drawing on bm2 if you're just going to throw it away and return bm instead.
Thomas Erichsen 3-Apr-20 10:56am    
Did you find the cause for your error? I am asking because I ran into identical symptoms, however my button.onclick routine does not include any graphics operations, it just fails on 2nd click before it enters the event handler...
Cody O'Meara 19-Apr-20 15:06pm    
Hello! Unfortunately I was unable to get it to work properly. I ended up doing something else. It wasn't as good as this could of been unfortunately.

1 solution

Generic GDI+ errors are always difficult as they provide so little information. However, given that you are trying to write to a hardcoded file address it most likely is file permissions, sharing violation or something similar. Try using a save dialog to write to different locations and see whether that resolves it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900