如何在picturebox中获取动态图像 [英] how to get dynamically images in picturebox

查看:146
本文介绍了如何在picturebox中获取动态图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends,

我正在尝试在C#win中动态添加图片框。形成。它是bing loded,但当我想获得picturebox图像即。 PictureBox.Image然后它给我空值。假设我有20个图片框然后开始2-3 Picturebox.Image不是null但其余的是null ...



我的代码



private void button2_Click(object sender,EventArgs e)

{

if(folderpath.ShowDialog()== DialogResult.OK)

{

string path = folderpath.SelectedPath;



DirectoryInfo di = new DirectoryInfo(path);



FileInfo [] Images = di.GetFiles(*。jpg);







foreach(var img in Images)

{

PictureBox picture = new PictureBox

{

名称=pictureBox+ i,

尺寸=新尺寸(316,320),

位置=新点(i * 316, 1),



SizeMode = PictureBoxSizeMode.AutoSize

};

if(img.Name.Substring(0,5)==Errod)

{

picture.ImageLocation = img.FullName;

ErrodImg.Add(图片);



ErrodImgpanel.Controls.Add(图片);

}

其他

{

图片.ImageLocation = img.FullName;

OriginalImg.Add(图片);

OriginalImgpanel.Controls.Add(图片);

}

i ++;

}

}



}



请帮我解决这个问题



感谢Adv ance。

Hello Friends,
I am Trying to add the picturebox dynamically in my C# win. form. it is bing loded but when i am trying to get picturebox image ie. PictureBox.Image then it is giving me null value. Suppose i have 20 picturebox then starting 2-3 Picturebox.Image is not null but rest of are null...

My code

private void button2_Click(object sender, EventArgs e)
{
if (folderpath.ShowDialog() == DialogResult.OK)
{
string path = folderpath.SelectedPath;

DirectoryInfo di = new DirectoryInfo(path);

FileInfo[] Images = di.GetFiles("*.jpg");



foreach (var img in Images)
{
PictureBox picture = new PictureBox
{
Name = "pictureBox" + i,
Size = new Size(316, 320),
Location = new Point(i * 316, 1),

SizeMode = PictureBoxSizeMode.AutoSize
};
if (img.Name.Substring(0, 5) == "Errod")
{
picture.ImageLocation = img.FullName;
ErrodImg.Add(picture);

ErrodImgpanel.Controls.Add(picture);
}
else
{
picture.ImageLocation = img.FullName;
OriginalImg.Add(picture);
OriginalImgpanel.Controls.Add(picture);
}
i++;
}
}

}

please help me out for this problem

thanks in Advance.

推荐答案

我在C#中创建了一个小项目,您可以从目录中加载图像并显示。



它的Dropbox下载



如果您对结果感到满意,请记得接受我的结果。



https://www.dropbox.com/sh/xe7qjgu6yh2c3mq/D6RZhmoh5R



祝你好运
I Have created you a small project in C# That you can load images from a directory and display.

its a Dropbox download

If you are happy with the results please remember to accept my result.

"https://www.dropbox.com/sh/xe7qjgu6yh2c3mq/D6RZhmoh5R"

Good Luck


这篇关于如何在picturebox中获取动态图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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