网页生成工具,图片格式转换,文件夹相关

来源:互联网 发布:守望先锋各个性能数据 编辑:程序博客网 时间:2024/05/18 15:07
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing.Imaging;using System.IO;namespace 网页生成工具{    public partial class Form1 : Form    {        public Form1( )        {            InitializeComponent ();        }        string imageAdd;        string fileName;        string txt;        private void button2_Click(object sender, EventArgs e)        {            openFileDialog1.Filter = "ALL file|*.*|bmp file|*.bmp|jpeg file|*.jpg|gif file|*.gif";//过滤文件            if (openFileDialog1.ShowDialog () == DialogResult.OK)            {                int num = openFileDialog1.SafeFileName.IndexOf (".");                fileName = openFileDialog1.SafeFileName.Remove(num);                try                {                    Bitmap bt = new Bitmap (openFileDialog1.FileName);//button2_Click里面所使用的pictureBox1.Image.Save方法必须通过Bitmap才能使用                    this.pictureBox1.Image = bt;//若此处两行改为pictureBox1.Load方法则,button2_Click里面所使用的pictureBox1.Image.Save出错!                }                catch (Exception)//异常处理                {                    MessageBox.Show ("不支持该文件类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);                }            }            textBox1.Text = fileName;                   }        private void button1_Click(object sender, EventArgs e)        {                imageAdd=textBox2.Text+ @"\"+fileName+".jpg";                pictureBox1.Image.Save (imageAdd, ImageFormat.Jpeg);                FileStream fs1 = new FileStream (textBox2.Text + @"\" + fileName + ".htm", FileMode.Create, FileAccess.Write);//创建写入文件                 StreamWriter sw = new StreamWriter (fs1,Encoding.Default);                imageAdd = "\"" + imageAdd + "\"";                txt=string.Format("<img src={0} border="+"0"+"></body></html>",imageAdd);                sw.WriteLine ("<html><head><title>123</title></head><body>", System.Text.Encoding.UTF8);                sw.WriteLine (txt,System.Text.Encoding.Default);                sw.Close();                fs1.Close ();                MessageBox.Show ("生成成功");        }        private void Form1_Load(object sender, EventArgs e)        {            textBox2.Text=@"C:\网页文件";        }        private void button4_Click(object sender, EventArgs e)        {            System.Diagnostics.Process.Start ("Explorer.exe", textBox2.Text);        }    }}

0 0
原创粉丝点击