generic error occurred in gdi+

For two out of the last ten files I used with the attached code, VB.NET returned this error.

Is there anything I could or should be doing in the code to avoid the problem?

Thanks.


Public Function ConvertFileToImage(ByVal fi_name As String, ByRef lex As LastException) As Boolean

        Dim img As System.Drawing.Image
        Dim retval As Boolean = True

        Try

            img = Image.FromFile(fi_name)

            If retval Then

                MyImage = img

            End If


        Catch ex As Exception
            retval = False
            lex.Message = ex.Message
            If Not ex.InnerException Is Nothing Then
                lex.Detail = ex.InnerException.Message
            End If
            lex.Source = "PageFileClass - ConvertFileToImage"
            lex.Code = "System Exception"


        End Try

        Return retval

    End Function

Open in new window

codefingerAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
You aren't doing anything wrong in the code...

Either:
(1) The images have something wrong them
(2) You have some kind of access error (permissions or file in use?)
0
 
codefingerAuthor Commented:
Too bad.  If my code is OK, there is nothing else I can do.
But thanks for your answer, at least I won't waste any time on it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.