转换乘法图像(在listview中加载) [英] Converting multiply images (loaded in listview)

查看:102
本文介绍了转换乘法图像(在listview中加载)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,

我正在编写一个应用程序,应该将图像列表转换为自己的大小(x / y)和格式

代码有效,我可以预览,转换图像并更改其大小(x / y)和输出格式,



我通过openfiledialog打开文件路径作为字符串,并将它们列在一个listview

示例:c\users \mick \ download = \\ Image.jpg

项目:c\users \mick \downloads

sub1:\ image001

sub2:.jpg



问题是:

转换1图像顺利,它的工作方式我想要它

选择多于1个图像然后转换它,给我所有相同的图像作为顶部选择



例如:

我选择Image001,Image002,Image003,Image004,Image005和Image006

我转换所选图像,但它会给我6x Image001 ...



代码如下,有人可以看一下吗?

谢谢你...







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 filepath as 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

Problem is:
Converting 1 image goes well, it works the way i want it
Selecting more then 1 image and then convert it, gives me all the same images as top selected

For 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...



''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

推荐答案

中为每个项目作为ListViewItem在ListView1.SelectedItems 你的循环变量是 item 。这是你应该用来提取数据,但你正在做其他事情(我不想分析究竟是什么,你没有使用 item ,甚至不是,所以无论如何都是错的。



并且没有必要得到 item.ItemIndex ,因为当前项目引用已在循环中可用。



修复它并且它将起作用。



-SA
In For Each item As ListViewItem In ListView1.SelectedItems your loop variable is item. This is what you should use to extract data, but you are doing something else (I don''t want to analyze what exactly, you are not using item, not even i, so it''s all wrong anyway).

And there is no a need to get item.ItemIndex, as the current item reference is already available inside the loop.

Fix it and it will work.

—SA


这篇关于转换乘法图像(在listview中加载)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆