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)

            End If

            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
            If txtFileName.Text = "" Then
                MsgBox("Please Enter FileName of an Image.")

                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)

            End If
        Catch ex As Exception
        End Try
    End Sub
End Class

Recommended Answers

Please read this FAQ.

Jump to Post

All 3 Replies

Please read this FAQ.

Please read this FAQ.

thanks for giving the link.
i will try it...

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.