推荐个c#提取程序图标/提取快捷方式图标的IconUtilities库
By
admin
at 2023-08-16 • 0人收藏 • 591人看过
这里推荐一个不错的图标提取库,可以提取提取某些程序的图标,如微信、QQ等 各种大小而不失真的图标(如果本身程序图标就没有比较大的图标话,也是提取不到),同时也可以提取快捷方式、文件、文件夹 等的图标。
首先去Nuget搜索IconUtilities并下载安装。
然后直接下面一行代码即可搞定。
Icon icon = IconUtilities.ExtractIcon(filePath, iconSize);
具体工程如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection.Emit; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace IconGet { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(textBox1.Text)) { MessageBox.Show("No Data"); return; } IconSize iconSize; if (radioButton1.Checked) { iconSize = IconSize.Small; } else if (radioButton2.Checked) { iconSize = IconSize.Large; } else if (radioButton3.Checked) { iconSize = IconSize.ExtraLarge; } else { iconSize = IconSize.Jumbo; } Icon icon = IconUtilities.ExtractIcon(textBox1.Text, iconSize); pictureBox1.Image = icon.ToBitmap(); } private void Form1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length > 0) { string filePath = files[0]; textBox1.Text = filePath; } } private void Form1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } } private void button2_Click(object sender, EventArgs e) { if (pictureBox1.Image!=null) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); //设置保存文件的格式 saveFileDialog1.Filter = "ICON文件|*.ico|位图文件|*.bmp|JPEG图片|*.jpg|PNG文件|*.png"; //弹出保存文件对话框 DialogResult result = saveFileDialog1.ShowDialog(); //当用户选中确定按钮后 if (result == DialogResult.OK) { //将picturebox的image图片保存到此路径 pictureBox1.Image.Save(saveFileDialog1.FileName); } } } } }
源代码工程如下:
编译好的软件exe下载:
1 个回复 | 最后更新于 2023-08-16
![aubreychao](/upload/avatar/middle/459.png)
aubreychao
2023-08-16
#1
登录后方可回帖