hi guys,, this is my problem
first im going to scan into a scanner, after that it loads into a picture box and when i save it i got an error said "A generic error occurred in GDI +" Can you help me guys

Thanks for your assistance
all comments are appreciated

Imports System
Imports System.IO
Imports WIALib
Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging

Public Class frmNewScan
    Dim WiaManager As New WIALib.WiaClass()
    Dim imageFileName As String = Path.GetTempFileName
    Private Sub frmNewScan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If WiaManager.Devices.Count > 0 Then

            Dim selectUsingUI As Object = System.Reflection.Missing.Value
            Dim wiaRoot As ItemClass = WiaManager.Create(0)

            Dim wiaObj As Object
            ' Dim typeItem As ItemClass
            'Dim wiaItem As ItemClass
            Dim wiaPics As CollectionClass = wiaRoot.GetItemsFromUI(WiaFlag.SingleImage, WiaIntent.ImageTypeColor)

            'wiaPics.Transfer("c:\", True)
            If Not IsDBNull(wiaPics.Count) Then
                For Each wiaObj In wiaPics
                    Dim wiaItem As ItemClass
                    wiaItem = CType(Marshal.CreateWrapperOfType(wiaObj, GetType(ItemClass)), ItemClass)

                    'create temporary file for image

                    'transfer picture to PictureBox
                    wiaItem.Transfer(imageFileName, False)
                    Me.PictureBox1.Load(imageFileName)

                Next
            End If

        Else
            MsgBox("No Scanner Connected", MsgBoxStyle.Information, "")
        End If
    End Sub

    Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
        Try
            If txtFileName.Text = "" Then
                MsgBox("Please Enter FileName of an Image.")
            Else

                Dim strBasePath As String
                Dim strFileName As String
                Dim pathfolder As String
                pathfolder = "\" + Main.txtempno.Text

                strFileName = txtFileName.Text
                strBasePath = ("D:\pics" & pathfolder)
                ' >> Check if Folder Exists 
                If Directory.Exists(strBasePath) = False Then
                    Call Directory.CreateDirectory(strBasePath)
                End If
                ' >> Save Picture 
                Call PictureBox1.Image.Save(strBasePath & "\" & strFileName, System.Drawing.Imaging.ImageFormat.Jpeg)


                MsgBox("Ok")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

''Chaitanya Solution'
myPath = "C:\badpic.GIF"
Dim myPic As New Bitmap(myPath)
Try
PictureBox1.Image = myPic
Catch ex As BadPicException
Console.Write("dd: " & ex.Message)
End Try

It dies at the "PictureBox1.Image = myPic" line

This article has been dead for over six months. Start a new discussion instead.