Sunday, 17 November 2013

c# image format converter



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private Bitmap map = null;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog old = new OpenFileDialog();
            old.Filter = comboBox1.Text + "|" + comboBox1.Text;
            string filter = old.Filter;
            old.InitialDirectory = System.Environment.CurrentDirectory;
            old.Title = "打开";
            old.ShowHelp = true;

            if (old.ShowDialog() == DialogResult.OK)
            {
                string name = old.FileName;
                map = new Bitmap(name);

                pictureBox1.Image = map;
                button2.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Title = "保存";
            sfd.OverwritePrompt = true;
            sfd.CheckPathExists = true;
            sfd.Filter = comboBox2.Text + "|" + comboBox2.Text;
            sfd.ShowHelp = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string name = sfd.FileName;
                map.Save(name);

            }

        }
    }
}

No comments:

Post a Comment