ALX
Well-known member
I run into an ocassional error in Sub MakeBMPCopy() when I save a bimap to a file.
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
The Error code and a portion of the stack trace:
System.Runtime.InteropServices.ExternalException was unhandled
ErrorCode=-2147467259
Message="A generic error occurred in GDI+."
Source="System.Drawing"
StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at System.Drawing.Image.Save(String filename)
at ...etc.
This is a single user machine and the file is not being used by another process. Can anyone deciper this error code: -2147467259 -or- (&h80004005) ?
	
		
			
		
		
	
				
			
			
				VB.NET:
			
		
		
		Private Function CopyRect(ByVal src As Form) As Bitmap
        Dim srcPic As Graphics = src.CreateGraphics
        Dim srcBmp As New Bitmap(Rect.Width, Rect.Height, srcPic)
        Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
        Dim HDC1 As IntPtr = srcPic.GetHdc
        Dim HDC2 As IntPtr = srcMem.GetHdc
        BitBlt(HDC2, 0, 0, Rect.Width, Rect.Height, HDC1, Rect.X, Rect.Y, 13369376)
        CopyRect = CType(srcBmp.Clone(), Bitmap)
        srcPic.ReleaseHdc(HDC1)
        srcMem.ReleaseHdc(HDC2)
        srcPic.Dispose()
        srcMem.Dispose()
    End Function
Private Sub MakeBMPCopy()
       [COLOR="SeaGreen"] '   This produces a smaller version of screenshot [/COLOR]
        Dim x As Integer
        Dim y As Integer
        Rect = New Rectangle(0, 0, Frm.Width, Frm.Height)
        ShrinkFactor = 0.75
        Dim p As New PictureBox
        ImagePath = "data1\bmps\snapshots\"
        Dim bmp As Bitmap = CopyRect(Frm)
        p.Size = bmp.Size
        x = CInt(p.Width * ShrinkFactor)
        y = CInt(p.Height * ShrinkFactor)
        p.Image = bmp
        p.Image = p.Image.GetThumbnailImage(x, y, AddressOf Dummy, System.IntPtr.Zero)
        Try
          [COLOR="red"] '  Here's where my error occurs...
             I can run the process maybe three or four times before the 
             error occurs...[/COLOR]      
       p.Image.Save(BaseDir & ImagePath & Filename1 & ".bmp")
        Catch ex As Exception
        End Try
        p.Dispose()
    End Sub
	The Error code and a portion of the stack trace:
System.Runtime.InteropServices.ExternalException was unhandled
ErrorCode=-2147467259
Message="A generic error occurred in GDI+."
Source="System.Drawing"
StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at System.Drawing.Image.Save(String filename)
at ...etc.
This is a single user machine and the file is not being used by another process. Can anyone deciper this error code: -2147467259 -or- (&h80004005) ?
			
				Last edited: