将图像添加到图像列表时出现内存不足异常 [英] out of memory exception when add image to imagelist

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

问题描述

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

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

推荐答案

首先,并非文件夹中的所有文件都是图像,并且您试图将不是图像文件的文件加载到

First, not all files in your folder are images and you are attempting to load a file that is not an image file into

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.


在.aspx中,您可以这样做:-

In .aspx u can do like this : -

<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/[^]


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

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