fisherboy998
New member
- Joined
- May 17, 2013
- Messages
- 4
- Programming Experience
- Beginner
Ok,
I'm writing a app that should convert a list of images to own size (x/y) and format
The code works, i can preview, convert the image and change its size (x/y), and output format,
I open the filespath of the images as a string via openfiledialog, and list them in a listview
example: c\users\mick\download\Image001.jpg
Item: c\users\mick\downloads
sub1: \image001
sub2: .jpg
Now my problem is:
Converting 1 image goes well, it works the way i want it, gives the size and output as i like...
Selecting more then 1 image and then convert it, gives me all the same images as top selected
I know the problem is within my coding, but i cant find a solution... can somebody help me ou with a new piece of code?
My problem example:
I select Image001, Image002, Image003, Image004, Image005, and Image006
I convert the selected images, but it wil give me 6x Image001...
the code is below, can somebody please have a look at it?
Thank you...
Code:
'Opening more then 1 file'
Dim ofd As New OpenFileDialog()
ofd.Multiselect = True
If ofd.ShowDialog() = DialogResult.OK Then
For Each file In ofd.FileNames
Dim path As String = System.IO.Path.GetDirectoryName(file)
Dim extension As String = System.IO.Path.GetExtension(file)
Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(file)
Dim lvitem As ListViewItem = ListView1.Items.Add(path)
lvitem.SubItems.Add(filename)
lvitem.SubItems.Add(extension)
Next
End If
'Code for converting and saving'
Dim i As Integer
For Each item As ListViewItem In ListView1.SelectedItems
i = item.Index
'Convert size'
Dim original As Image = Image.FromFile(ListView1.SelectedItems(0).Text & "\" & ListView1.SelectedItems(0).SubItems(1).Text & ListView1.SelectedItems(0).SubItems(2).Text)
Dim newbmp As New Bitmap(original, 1600, 1200)
Dim gp As Graphics = Graphics.FromImage(newbmp)
'Check if the directory exists'
Dim strfilename As String
If Not My.Computer.FileSystem.DirectoryExists("C:\Users\Mick\Desktop\Screenshot") Then
My.Computer.FileSystem.CreateDirectory("C:\Users\Mick\Desktop\Screenshot")
End If
'Count how many files are in the directory'
Dim counter = My.Computer.FileSystem.GetFiles(C:\Users\Mick\Desktop\Screenshot)
Dim intCount As Integer
intCount = CStr(counter.Count)
'Output name and file format'
If ComboBox1.SelectedItem = ".Jpeg" Then
strfilename = "Image" & intCount + 1
newbmp.Save(C:\Users\Mick\Desktop\Screenshot\ & strfilename & .jpeg, System.Drawing.Imaging.ImageFormat.Jpeg)
end if
I'm writing a app that should convert a list of images to own size (x/y) and format
The code works, i can preview, convert the image and change its size (x/y), and output format,
I open the filespath of the images as a string via openfiledialog, and list them in a listview
example: c\users\mick\download\Image001.jpg
Item: c\users\mick\downloads
sub1: \image001
sub2: .jpg
Now my problem is:
Converting 1 image goes well, it works the way i want it, gives the size and output as i like...
Selecting more then 1 image and then convert it, gives me all the same images as top selected
I know the problem is within my coding, but i cant find a solution... can somebody help me ou with a new piece of code?
My problem example:
I select Image001, Image002, Image003, Image004, Image005, and Image006
I convert the selected images, but it wil give me 6x Image001...
the code is below, can somebody please have a look at it?
Thank you...
Code:
'Opening more then 1 file'
Dim ofd As New OpenFileDialog()
ofd.Multiselect = True
If ofd.ShowDialog() = DialogResult.OK Then
For Each file In ofd.FileNames
Dim path As String = System.IO.Path.GetDirectoryName(file)
Dim extension As String = System.IO.Path.GetExtension(file)
Dim filename As String = System.IO.Path.GetFileNameWithoutExtension(file)
Dim lvitem As ListViewItem = ListView1.Items.Add(path)
lvitem.SubItems.Add(filename)
lvitem.SubItems.Add(extension)
Next
End If
'Code for converting and saving'
Dim i As Integer
For Each item As ListViewItem In ListView1.SelectedItems
i = item.Index
'Convert size'
Dim original As Image = Image.FromFile(ListView1.SelectedItems(0).Text & "\" & ListView1.SelectedItems(0).SubItems(1).Text & ListView1.SelectedItems(0).SubItems(2).Text)
Dim newbmp As New Bitmap(original, 1600, 1200)
Dim gp As Graphics = Graphics.FromImage(newbmp)
'Check if the directory exists'
Dim strfilename As String
If Not My.Computer.FileSystem.DirectoryExists("C:\Users\Mick\Desktop\Screenshot") Then
My.Computer.FileSystem.CreateDirectory("C:\Users\Mick\Desktop\Screenshot")
End If
'Count how many files are in the directory'
Dim counter = My.Computer.FileSystem.GetFiles(C:\Users\Mick\Desktop\Screenshot)
Dim intCount As Integer
intCount = CStr(counter.Count)
'Output name and file format'
If ComboBox1.SelectedItem = ".Jpeg" Then
strfilename = "Image" & intCount + 1
newbmp.Save(C:\Users\Mick\Desktop\Screenshot\ & strfilename & .jpeg, System.Drawing.Imaging.ImageFormat.Jpeg)
end if