7,655
社区成员
发帖
与我相关
我的任务
分享
private void Init()
{
static private string[] photos;//获取图片
photos = Directory.GetFiles(PhotoDirectory, @"*.PNG");
int count = 0;
Bitmap bitmap;
this.imageList.Images.Clear();
ListViewItem listViewItem = null;
listView_photos.Items.Clear();
if ((Photos == null) || (Photos.Length < 1))
{
this.Close();
}
if (Photos != null)
{
count = Photos.Length;
for (int i = 0; i < count; i++)
{
bitmap = new Bitmap(Photos[i]);
imageList.Images.Add(bitmap);
listViewItem = new ListViewItem();
listViewItem.SubItems.Add(i.ToString());
listViewItem.ImageIndex = i;
listView_photos.Items.Add(listViewItem);
}
}
}
//采用listview方式显示图片
private void getphotolist2()
{
imageList1.ImageSize = new Size(40,40);
string[] filelist = null;
string PDApath = MovePoliceAKE8.comm.constant.pdaFilePath;
//返回指定目录的所有文件
if (System.IO.Directory.Exists(PDApath))
{
filelist = System.IO.Directory.GetFiles(PDApath);
for (int ii = 0; ii < filelist.Length; ii++)
{
try
{
//filelist[ii].ToString()为我的JPG图片地址
Bitmap btm= new Bitmap(filelist[ii].ToString());
//循环显示第二个图标的时候出错语句。错误信息为“outofmemoryerror”
imageList1.Images.Add((Image.FromHbitmap(btm.GetHbitmap())));
listView1.SmallImageList = imageList1;
ListViewItem lst = new ListViewItem("第"+ii+"张图片");
listView1.Items.Add(lst);
listView1.Items[ii].ImageIndex = ii;
btm.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}