Tuesday, December 7, 2010

How to copy and save all images displaying in a picture box, from a listbox (Using For...Loop)

    Dim Fold As New DirectoryInfo(C:\Users\User\Desktop\OldFotos)

            Dim strNewLoc As New DirectoryInfo(C:\Users\User\Desktop\NewFotos)

            For Each newImg As String In Me.lstImages.SelectedItem.ToString
                Dim strName As String = Me.lstImages.SelectedItem.ToString
                Dim strImg As Bitmap = Me.PbxImages.BackgroundImage

                Dim intImg As Integer = Math.Abs(Me.lstImages.SelectedIndex + 1)

                'Imports the image displayed
                strImg.Save(strNewLoc.ToString & "\" & strName & ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)

                'Selects the next image to be displayed
                Dim strNxtImg As String = Me.lstImages.Items.Item(intImg).ToString

                'Me.PbxImages.BackgroundImage = Nothing
                Me.PbxImages.BackgroundImage = Image.FromFile(Fold.ToString & "\" & strNxtImg)
                Me.lstImages.SelectedIndex = intImg


                If Me.lstImages.Items.Count = Me.lstImages.SelectedIndex + 1 Then
                    Exit For
                End If
            Next

No comments:

Post a Comment