如何将图片从picturebox导出到列表框 [英] how to export picture from picturebox to listbox

查看:75
本文介绍了如何将图片从picturebox导出到列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

i有关于从picturebox到listbox的导出图片的问题,我想使用添加按钮将图片从picturebox导出到listbox ...

hi!
i have problem about export picture from picturebox to listbox, i want to use add button to export the picture from picturebox to listbox...

推荐答案

您将能够在CodeProject上找到足够的代码: http://www.codeproject.com/search.aspx?q=Web+camera+capture+Forms&doctypeid=1 [ ^ ]。



-SA
You will be able to find enough of code on CodeProject: http://www.codeproject.com/search.aspx?q=Web+camera+capture+Forms&doctypeid=1[^].

—SA


你好Renz Pelias,



这是一个可运行的例子 - 请将图片路径(D:\sample.jpg)替换为系统的有效路径:



Hi Renz Pelias,

Here is a runnable example - please replace the picture path (D:\sample.jpg) to a valid path for your system:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace AddPictureToListView
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Form form = new Form();

            PictureBox pb = new PictureBox { Dock = DockStyle.Top, Image = Bitmap.FromFile(@"D:\sample.jpg") };
            ListView lv = new ListView { Dock = DockStyle.Fill };
            lv.LargeImageList = new ImageList();

            Button button = new Button { Text = "Add", Dock = DockStyle.Top};

            button.Click += (object sender, EventArgs e) =>
                {
                    string strKey = "Image" + lv.LargeImageList.Images.Count; 
                    lv.LargeImageList.Images.Add(strKey, pb.Image);

                    ListViewItem item = new ListViewItem("Text representing image", strKey);
                    item.Tag = pb.Image;   
                    
                    lv.Items.Add(item);
                };

            form.Controls.Add(lv);
            form.Controls.Add(button);
            form.Controls.Add(pb);

            Application.Run(form);
        }
    }
}





所以诀窍是填写图像列表并将listview项目连接到它。我还将原始图像作为标记添加到ListViewItem(如果您以后想要对原始文件执行某些操作,则可能很好)。有两种方法可以使用键连接图像 - 我在示例中使用的方法或仅通过索引(对于静态图像列表更有用)。



但我不得不说ListView可能不适合你的用例。您还可以使用Panel(Wrap,Panel)并添加PictureBoxes(或者所有者绘制它以获得更好的性能)。 (不要忘记打开滚动...)



如果您有任何其他问题,请随时询问 - 快乐编码



亲切的问候

Johannes



So the trick is to fill the image list(s) and wire up the listview items to it. I also added the original Image as Tag to the ListViewItem (maybe nice if you later want to do something with the original). There are two ways to wire the Images up, with keys - the approach I used in the example or just by index (more usefull for static Image list).

But I have to say that maybe a ListView is not ideal for your usecase. You can also use a Panel (Wrap,Panel) and just add PictureBoxes (or owner-draw it for better Performance) to it. (Don't forget to turn Scrolling on...)

If you have any further questions, feel free to ask - happy coding

Kind regards
Johannes


这篇关于如何将图片从picturebox导出到列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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