原文路径:
http://www.cnblogs.com/xiexiaomin/articles/1716464.html
先转存下来,以后有时间慢慢研究
代码
public partial class IconMake : Window
{
Bitmap srcBitmap = null;//用于保存原图
System.Drawing.Size size;//用于保存目标图标的大小
{
Bitmap srcBitmap = null;//用于保存原图
System.Drawing.Size size;//用于保存目标图标的大小
public IconMake()
{
InitializeComponent();
}
{
InitializeComponent();
}
private void cmbSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cmbSize.SelectedIndex == 0)
size = new System.Drawing.Size(16, 16);
else if (cmbSize.SelectedIndex == 1)
size = new System.Drawing.Size(32, 32);
else if (cmbSize.SelectedIndex == 2)
size = new System.Drawing.Size(64, 64);
}
{
if (cmbSize.SelectedIndex == 0)
size = new System.Drawing.Size(16, 16);
else if (cmbSize.SelectedIndex == 1)
size = new System.Drawing.Size(32, 32);
else if (cmbSize.SelectedIndex == 2)
size = new System.Drawing.Size(64, 64);
}
private void btnOk_Click(object sender, RoutedEventArgs e)
{
//弹出对话框
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = "F:\";
dlg.Filter = "图片(*.jpg,*.png,*.bmp)|*.jpg;*.png;*.bmp";
dlg.ValidateNames = true;
dlg.CheckFileExists = true;
dlg.CheckPathExists = true;
//Nullable result = dlg.ShowDialog();
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txtImage.Text = dlg.FileName;
srcBitmap = new Bitmap(dlg.FileName);
imgJpeg.Source = new BitmapImage(new Uri(txtImage.Text, UriKind.RelativeOrAbsolute));
}
}
{
//弹出对话框
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = "F:\";
dlg.Filter = "图片(*.jpg,*.png,*.bmp)|*.jpg;*.png;*.bmp";
dlg.ValidateNames = true;
dlg.CheckFileExists = true;
dlg.CheckPathExists = true;
//Nullable result = dlg.ShowDialog();
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txtImage.Text = dlg.FileName;
srcBitmap = new Bitmap(dlg.FileName);
imgJpeg.Source = new BitmapImage(new Uri(txtImage.Text, UriKind.RelativeOrAbsolute));
}
}
private void btnMake_Click(object sender, RoutedEventArgs e)
{
try
{
if (txtImage.Text != "" && cmbSize.Text != "")
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "图标(*.ico)|*.ico";
dlg.CheckPathExists = true;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
FileStream fs = new FileStream(dlg.FileName, FileMode.Create);
System.Drawing.Icon icon = ConvertBitmap2Ico(srcBitmap);
//将Icon保存的指定的输出
{
try
{
if (txtImage.Text != "" && cmbSize.Text != "")
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "图标(*.ico)|*.ico";
dlg.CheckPathExists = true;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
FileStream fs = new FileStream(dlg.FileName, FileMode.Create);
System.Drawing.Icon icon = ConvertBitmap2Ico(srcBitmap);
//将Icon保存的指定的输出