将图像添加到图像列表时出现内存不足异常

将图像添加到图像列表时出现内存不足异常

本文介绍了将图像添加到图像列表时出现内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
尝试从文件夹查看图像到列表视图时出现异常
我用了这段代码

hi all
i have an exception when try to view images from folder to listview
i used this code

DirectoryInfo dir  = new DirectoryInfo(pth);
              foreach (FileInfo file in dir.GetFiles())
              {
                  this.imageList1.Images.Add(Image.FromFile(file.FullName));
              }
              for (int j = 0; j < this.imageList1.Images.Count; j++)
              {
                  ListViewItem item = new ListViewItem();
                  item.ImageIndex = j;
                  this.listView1.Items.Add(item);



而且我不知道怎么了
请帮忙
谢谢u



and i do not know what is the wrong
please help
thank u

推荐答案

this.imageList1.Images.Add(Image.FromFile(file.FullName));



抛出file.FullName OutOfMemory异常中包含的字符串.

请参阅验证文件为JPEG的解决方案二 [ ^ ]关于如何从目录.



The the string contained in file.FullName an OutOfMemory Exception is thrown.

See solution two of Verifying a file is JPEG[^] on how to pick certain image files from a directory.


<itemtemplate>
<img src="<%# Eval("path") %>" />
</itemtemplate>




或尝试以下方法:- http://www.c-sharpcorner.com/uploadfile/e628d9/inserting-retrieving-images-from-sql-server-database-without-using-stored-procedures/ [ ^ ]




or try this one :- http://www.c-sharpcorner.com/uploadfile/e628d9/inserting-retrieving-images-from-sql-server-database-without-using-stored-procedures/[^]


这篇关于将图像添加到图像列表时出现内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 01:30