如何获取imageList图片保存到本地

今天在写C#程序的时候,想用图片可我之前的图片找不到了。

但是之前程序里面 imageList 有图片,可是嵌入里面了。

怎么把C# imageList 里面的图片保存到本地呢?

 

我们建立一个C#窗体测试程序,

把有图片的 imageList ,复制到 测试程序 里面。

我查资料后自己写了一个方法,成功取到图片;

 

复制代码
 1         /// <summary>
 2         /// 获取imageList里面图片,保存到指定路径文件夹中
 3         /// </summary>
 4         /// <param name="imageList">待提取图片的imageList</param>
 5         /// <param name="path">想要保存图片的文件夹路径,注意文件夹想要存在</param>
 6         /// <returns></returns>
 7         private bool GetImageListSave(ImageList imageList, string path)
 8         {
 9             if (imageList.Images.Count <= 0)
10             {
11                 return false;
12             }
13             for (int i = 0; i < imageList1.Images.Count; i++)
14             {
15                 try
16                 {
17                     imageList1.Images[i].Save(path + "\\" + imageList1.Images.Keys[i]);
18                 }
19                 catch (Exception ex)
20                 {
21                     MessageBox.Show("保存图片错误:" + ex.Message);
22                     return false;
23                 }              
24             }
25             return true;
26         }
复制代码

 

 

 

获取的图像如下图

 

 

posted @   funiyi816  阅读(904)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示