I have a text file which contains the data of an image (path, latitude and longitude). the textfile is place in a listview and the data in textfile is place in textboxes. if i click one item in listview then click save. it will create an image containing the data in the text file, the problem is if the textfile contains a 20,000 rows then call by the system. you need to click all the data in rows one by one and click save one by on, not user friendly and too risky.
now my Questions is:
Is it possible to save all item in a listview in a single click of button. Here is my code for saving the all item in listview.
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btnsave.Click
Dim n As Integer
'line to save the specific file
For n = 0 To LV.Items.Count + 1 ' <--- tthis line create more than one image
If EW.Copyright <> txtcopyright.Text Then
EW.Copyright = txtcopyright.Text
Update = True
End If
If EW.Description <> txtdescription.Text Then
EW.Description = txtdescription.Text
Update = True
End If
EW.GPSLatitude = lat
Update = True
EW.GPSLongitude = Lon
Update = True
EW.GPSLatitudeRef = LatRef
EW.GPSLongitudeRef = LonRef
If Update Then
'Always update last mofified date
' EW.DateTimeLastModified = Now
'Get the updated image
Dim newImage As Bitmap = EW.GetBitmap
Dim Fi As IO.FileInfo = New IO.FileInfo(LV.SelectedItems(0).Text)
'Calculate a new filename
Dim NewFileName As String
Dim I As Integer = 0
Do
I += 1
NewFileName = txtpath.Text & " (" & I.ToString & ")"
txtpath.Text = NewFileName
NewFileName = IO.Path.Combine(Fi.DirectoryName, NewFileName & Fi.Extension)
Loop Until Not IO.File.Exists(NewFileName)
'Save the updated image file.
Select Case Fi.Extension.ToUpper
Case ".PNG"
newImage.Save(NewFileName, Drawing.Imaging.ImageFormat.Png)
Case ".JPG"
' JPG requires a trick for lossless saving
Dim NewFilenameTemp = NewFileName & ".temp"
' We rotate the image for 90 degrees aand save to temp
Dim Enc As Encoder = Encoder.Transformation
Dim EncParm As EncoderParameter
Dim EncParms As New EncoderParameters(1)
EncParm = New EncoderParameter(Enc, CLng(EncoderValue.TransformRotate90))
EncParms.Param(0) = EncParm
Dim CodecInfo As ImageCodecInfo = GetEncoderInfo("image/jpeg")
' Write the rotated image with new properties
newImage.Save(NewFilenameTemp, CodecInfo, EncParms)
' Release memory
newImage.Dispose()
newImage = Nothing
GC.Collect()
' Delete the original file
System.IO.File.Delete(NewFileName)
' Rotate back and save as new
newImage = Image.FromFile(NewFilenameTemp)
EncParm = New EncoderParameter(Enc, CLng(EncoderValue.TransformRotate270))
EncParms.Param(0) = EncParm
newImage.Save(NewFileName, CodecInfo, EncParms)
' Release memory
newImage.Dispose()
newImage = Nothing
GC.Collect()
' Delete the temporary file
System.IO.File.Delete(NewFilenameTemp)
Case Else
MsgBox("Can't save file types " & Fi.Extension)
End Select
End If
Next n
End Sub
Any Comments,Suggestion and idea that may help will highly appriciated.. Thanks in Advanced..
jonel