WPF学习生成ico图标_Andy_Issta_新浪博客


原文路径:
http://www.cnblogs.com/xiexiaomin/articles/1716464.html

先转存下来,以后有时间慢慢研究

  WPF学习生成ico图标


代码

 public partial class IconMake : Window
    {
        Bitmap srcBitmap = null;//用于保存原图
        System.Drawing.Size size;//用于保存目标图标的大小

        public IconMake()
        {
            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);
        }

        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));
            }
        }

        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保存的指定的输出
                 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

issta

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值