C#实现批量给图片添加水印的示例代码

.NET
314
0
0
2023-07-01
标签   C#
目录
  • 实践过程
  • 效果
  • 代码

实践过程

效果

代码

public partial class Form : Form
{
    public Form()
    {
        InitializeComponent();
    }


    #region 获取系统字体

    private void GetSystemFont(ToolStripComboBox cb)
    {
        InstalledFontCollection myFont = new InstalledFontCollection();
        foreach (FontFamily ff in myFont.Families)
        {
            cb.Items.Add(ff.Name);
        }

        cb.SelectedItem = "宋体";
    }

    #endregion

    private void Form_Load(object sender, EventArgs e)
    {
        cbbPosition.SelectedIndex =;
    }

    string[] ImgArray = null;
    string ImgDirectoryPath = null;

    private void btnLoadImg_Click(object sender, EventArgs e)
    {
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            lbImgList.Items.Clear();
            ImgArray = openFileDialog.FileNames;
            string ImgP = ImgArray[].ToString();
            ImgP = ImgP.Remove(ImgP.LastIndexOf("\\"));
            ImgDirectoryPath = ImgP;
            for (int i =; i < ImgArray.Length; i++)
            {
                string ImgPath = ImgArray[i].ToString();
                string ImgName = ImgPath.Substring(ImgPath.LastIndexOf("\\") +,
                    ImgPath.Length - ImgPath.LastIndexOf("\\") -);
                lbImgList.Items.Add(ImgName);
            }

            tsslStatus.Text = "图片总数:" + lbImgList.Items.Count;
        }
    }

    private void lbImgList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (lbImgList.SelectedItems.Count >)
        {
            tsslText.Text = "图片位置:" + ImgDirectoryPath + "\\" + lbImgList.SelectedItems[].ToString();
        }
    }

    private void btnPreview_Click(object sender, EventArgs e)
    {
        if (lbImgList.Items.Count >)
        {
            if (rbTxt.Checked)
            {
                if (txtWaterMarkFont.Text != "" && txtSavaPath.Text.Trim() != "")
                {
                    AddFontWatermark(txtWaterMarkFont.Text.Trim(), lbImgList.Items[].ToString(), 0);
                    Form frm2 = new Form2();
                    frm.ig = BigBt;
                    frm.ShowDialog();
                }
            }
            else
            {
                if (txtWaterMarkImg.Text != "" && txtSavaPath.Text != "")
                {
                    ChangeAlpha();
                    AddFontWatermark(txtWaterMarkFont.Text.Trim(), lbImgList.Items[].ToString(), 2);
                    Form frm2 = new Form2();
                    frm.ig = BigBt;
                    frm.ShowDialog();
                }
            }
        }
    }

    private void trackBar_Enter(object sender, EventArgs e)
    {
        lbImgList.Focus();
    }

    private void btnSelect_Click(object sender, EventArgs e)
    {
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            txtWaterMarkImg.Text = openFileDialog.FileName;
            if (rbPIC.Checked == true)
            {
                ChangeAlpha();
                pbImgPreview.Image = Image.FromFile(txtWaterMarkImg.Text.Trim());
            }
        }
    }

    private void rbTxt_CheckedChanged(object sender, EventArgs e)
    {
        trackBar.Enabled = false;
        if (rbPIC.Checked)
            pbImgPreview.Image = null;
    }

    private void rbPIC_CheckedChanged(object sender, EventArgs e)
    {
        trackBar.Enabled = true;
        if (rbTxt.Checked)
        {
            pbImgPreview.Image = null;
        }
    }

    private void button_Click(object sender, EventArgs e)
    {
        if (lbImgList.Items.Count >)
        {
            fontDialog.ShowColor = true;
            fontDialog.ShowHelp = false;
            fontDialog.ShowApply = false;
            if (fontDialog.ShowDialog() == DialogResult.OK)
            {
                FontF = fontDialog.Font.FontFamily;
                fontColor = fontDialog.Color;
                fontSize = fontDialog.Font.Size;
                fontStyle = fontDialog.Font.Style;
                AddFontWatermark(txtWaterMarkFont.Text.Trim(), lbImgList.Items[].ToString(), 0);
                pbImgPreview.Image = bt;
            }
        }
    }

    Bitmap bt = null;
    float fontSize =;
    Color fontColor = Color.Black;
    FontFamily FontF = null;
    FontStyle fontStyle = FontStyle.Regular;
    int Fwidth;
    int Fheight;
    Bitmap BigBt;
    Font f;
    Brush b;

    private void AddFontWatermark(string txt, string Iname, int i) //预览
    {
        b = new SolidBrush(fontColor);
        bt = new Bitmap(, 75);
        BigBt = new Bitmap(Image.FromFile(ImgDirectoryPath + "\\" + Iname));
        Graphics g = Graphics.FromImage(bt);
        Graphics g = Graphics.FromImage(BigBt);
        g.Clear(Color.Gainsboro);
        pbImgPreview.Image = bt;
        if (FontF == null)
        {
            f = new Font(txt, fontSize);
            SizeF XMaxSize = g.MeasureString(txt, f);
            Fwidth = (int) XMaxSize.Width;
            Fheight = (int) XMaxSize.Height;
            g.DrawString(txt, f, b, (int) ( - Fwidth) / 2, (int) (75 - Fheight) / 2);
            if (cbbPosition.SelectedIndex ==) //正中
            {
                g.DrawString(txt, f, b, (int) (BigBt.Width - Fwidth) / 2, (int) (BigBt.Height - Fheight) / 2);
            }

            if (cbbPosition.SelectedIndex ==) //左上
            {
                g.DrawString(txt, f, b, 30, 30);
            }

            if (cbbPosition.SelectedIndex ==) //左下
            {
                g.DrawString(txt, f, b, 30, (int) (BigBt.Height - Fheight) - 30);
            }

            if (cbbPosition.SelectedIndex ==) //右上
            {
                g.DrawString(txt, f, b, (int) (BigBt.Width - Fwidth), 30);
            }

            if (cbbPosition.SelectedIndex ==) //右下
            {
                g.DrawString(txt, f, b, (int) (BigBt.Width - Fwidth), (int) (BigBt.Height - Fheight) - 30);
            }
        }
        else
        {
            f = new Font(FontF, fontSize, fontStyle);
            SizeF XMaxSize = g.MeasureString(txt, f);
            Fwidth = (int) XMaxSize.Width;
            Fheight = (int) XMaxSize.Height;
            g.DrawString(txt, new Font(FontF, fontSize, fontStyle), b, (int) ( - Fwidth) / 2,
                (int) ( - Fheight) / 2);
            if (cbbPosition.SelectedIndex ==) //正中
            {
                g.DrawString(txt, new Font(FontF, fontSize, fontStyle), b, (int) (BigBt.Width - Fwidth) / 2,
                    (int) (BigBt.Height - Fheight) /);
            }

            if (cbbPosition.SelectedIndex ==) //左上
            {
                g.DrawString(txt, new Font(FontF, fontSize, fontStyle), b, 30, 30);
            }

            if (cbbPosition.SelectedIndex ==) //左下
            {
                g.DrawString(txt, new Font(FontF, fontSize, fontStyle), b, 30,
                    (int) (BigBt.Height - Fheight) -);
            }

            if (cbbPosition.SelectedIndex ==) //右上
            {
                g.DrawString(txt, new Font(FontF, fontSize, fontStyle), b, (int) (BigBt.Width - Fwidth), Fheight);
            }

            if (cbbPosition.SelectedIndex ==) //右下
            {
                g.DrawString(txt, new Font(FontF, fontSize, fontStyle), b, (int) (BigBt.Width - Fwidth),
                    (int) (BigBt.Height - Fheight) -);
            }
        }

        if (i ==)
        {
            string ipath;
            if (NewFolderPath.Length ==)
                ipath = NewFolderPath.Remove(NewFolderPath.LastIndexOf(":") +);
            else
                ipath = NewFolderPath;
            string imgstype =
                Iname.Substring(Iname.LastIndexOf(".") +, Iname.Length - 1 - Iname.LastIndexOf("."));
            if (imgstype.ToLower() == "jpeg" || imgstype.ToLower() == "jpg")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Jpeg);
            }

            if (imgstype.ToLower() == "png")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Png);
            }

            if (imgstype.ToLower() == "bmp")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Bmp);
            }

            if (imgstype.ToLower() == "gif")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Gif);
            }

            g.Dispose();
            BigBt.Dispose();
        }

        if (i ==)
        {
            if (cbbPosition.SelectedIndex ==) //正中
            {
                g.DrawImage(effect, (int) (BigBt.Width - effect.Width) / 2,
                    (int) (BigBt.Height - effect.Height) /);
            }

            if (cbbPosition.SelectedIndex ==) //左上
            {
                g.DrawImage(effect, 30, 30);
            }

            if (cbbPosition.SelectedIndex ==) //左下
            {
                g.DrawImage(effect, 30, (int) (BigBt.Height - effect.Height) - 30);
            }

            if (cbbPosition.SelectedIndex ==) //右上
            {
                g.DrawImage(effect, (int) (BigBt.Width - effect.Width) - 30, 30);
            }

            if (cbbPosition.SelectedIndex ==) //右下
            {
                g.DrawImage(effect, (int) (BigBt.Width - effect.Width) - 30,
                    (int) (BigBt.Height - effect.Height) -);
            }
        }

        if (i ==)
        {
            if (cbbPosition.SelectedIndex ==) //正中
            {
                g.DrawImage(effect, (int) (BigBt.Width - effect.Width) / 2,
                    (int) (BigBt.Height - effect.Height) /);
            }

            if (cbbPosition.SelectedIndex ==) //左上
            {
                g.DrawImage(effect, 30, 30);
            }

            if (cbbPosition.SelectedIndex ==) //左下
            {
                g.DrawImage(effect, 30, (int) (BigBt.Height - effect.Height) - 30);
            }

            if (cbbPosition.SelectedIndex ==) //右上
            {
                g.DrawImage(effect, (int) (BigBt.Width - effect.Width), 30);
            }

            if (cbbPosition.SelectedIndex ==) //右下
            {
                g.DrawImage(effect, (int) (BigBt.Width - effect.Width), (int) (BigBt.Height - effect.Height) - 30);
            }

            string ipath;
            if (NewFolderPath.Length ==)
                ipath = NewFolderPath.Remove(NewFolderPath.LastIndexOf(":") +);
            else
                ipath = NewFolderPath;
            string imgstype =
                Iname.Substring(Iname.LastIndexOf(".") +, Iname.Length - 1 - Iname.LastIndexOf("."));
            if (imgstype.ToLower() == "jpeg" || imgstype.ToLower() == "jpg")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Jpeg);
            }

            if (imgstype.ToLower() == "png")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Png);
            }

            if (imgstype.ToLower() == "bmp")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Bmp);
            }

            if (imgstype.ToLower() == "gif")
            {
                BigBt.Save(ipath + "\\_" + Iname, ImageFormat.Gif);
            }
        }
    }

    private void txtWaterMarkFont_TextChanged(object sender, EventArgs e)
    {
        if (lbImgList.Items.Count <=)
        {
            MessageBox.Show("请加载图片", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
        }
        else
        {
            AddFontWatermark(txtWaterMarkFont.Text.Trim(), lbImgList.Items[].ToString(), 0);
            pbImgPreview.Image = bt;
        }
    }

    private void btnExit_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    /// <summary>
    /// 调节透明度
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    Bitmap effect;

    Bitmap source;
    Image new_img;

    private void ChangeAlpha()
    {
        pbImgPreview.Refresh();
        source = new Bitmap(Image.FromFile(txtWaterMarkImg.Text.Trim()));
        if (source.Width <=)
            effect = new Bitmap(, 75);
        else
        {
            Image.GetThumbnailImageAbort callb = null;
            //对水印图片生成缩略图,缩小到原图得/4
            new_img = source.GetThumbnailImage(source.Width /, source.Width / 4, callb, new System.IntPtr());
            effect = new Bitmap(this.new_img.Width, this.new_img.Height);
        }

        Graphics _effect = Graphics.FromImage(effect);
        float[][] matrixItems =
        {
            new float[] {, 0, 0, 0, 0},
            new float[] {, 1, 0, 0, 0},
            new float[] {, 0, 1, 0, 0},
            new float[] {, 0, 0, 0, 0},
            new float[] {, 0, 0, trackBar1.Value / 255f, 1}
        };
        ColorMatrix imgMatrix = new ColorMatrix(matrixItems);
        ImageAttributes imgEffect = new ImageAttributes();
        imgEffect.SetColorMatrix(imgMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        if (source.Width <=)
        {
            _effect.DrawImage(source, new Rectangle(, 0, 368, 75), 0, 0, 368, 75, GraphicsUnit.Pixel, imgEffect);
        }
        else
        {
            _effect.DrawImage(new_img, new Rectangle(, 0, new_img.Width, new_img.Height), 0, 0, new_img.Width,
                new_img.Height, GraphicsUnit.Pixel, imgEffect);
        }

        pbImgPreview.Image = effect;
    }

    private void trackBar_ValueChanged(object sender, EventArgs e)
    {
        if (rbPIC.Checked && txtWaterMarkImg.Text.Trim() != "")
            ChangeAlpha();
    }

    private void btnPerform_Click(object sender, EventArgs e)
    {
        if (rbTxt.Checked && txtSavaPath.Text != "" && txtWaterMarkFont.Text != "")
        {
            for (int i =; i < lbImgList.Items.Count; i++)
            {
                AddFontWatermark(txtWaterMarkFont.Text.Trim(), lbImgList.Items[i].ToString(),);
            }

            MessageBox.Show("添加水印成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        if (rbPIC.Checked && txtSavaPath.Text != "" && pbImgPreview.Image != null)
        {
            for (int i =; i < lbImgList.Items.Count; i++)
            {
                AddFontWatermark(txtWaterMarkFont.Text.Trim(), lbImgList.Items[i].ToString(),);
            }

            MessageBox.Show("添加水印成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }

    string NewFolderPath;

    private void button_Click(object sender, EventArgs e)
    {
        if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
        {
            txtSavaPath.Text = folderBrowserDialog.SelectedPath;
            NewFolderPath = txtSavaPath.Text.Trim();
        }
    }
}
partial class Form
{
/// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows 窗体设计器生成的代码

    /// <summary>
    /// 设计器支持所需的方法 - 不要
    /// 使用代码编辑器修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
        this.colorDialog = new System.Windows.Forms.ColorDialog();
        this.statusStrip = new System.Windows.Forms.StatusStrip();
        this.tsslStatus = new System.Windows.Forms.ToolStripStatusLabel();
        this.tsslText = new System.Windows.Forms.ToolStripStatusLabel();
        this.splitContainer = new System.Windows.Forms.SplitContainer();
        this.groupBox = new System.Windows.Forms.GroupBox();
        this.lbImgList = new System.Windows.Forms.ListBox();
        this.button = new System.Windows.Forms.Button();
        this.txtSavaPath = new System.Windows.Forms.TextBox();
        this.label = new System.Windows.Forms.Label();
        this.btnPreview = new System.Windows.Forms.Button();
        this.btnExit = new System.Windows.Forms.Button();
        this.btnPerform = new System.Windows.Forms.Button();
        this.btnLoadImg = new System.Windows.Forms.Button();
        this.groupBox = new System.Windows.Forms.GroupBox();
        this.label = new System.Windows.Forms.Label();
        this.label = new System.Windows.Forms.Label();
        this.cbbPosition = new System.Windows.Forms.ComboBox();
        this.label = new System.Windows.Forms.Label();
        this.button = new System.Windows.Forms.Button();
        this.trackBar = new System.Windows.Forms.TrackBar();
        this.rbPIC = new System.Windows.Forms.RadioButton();
        this.rbTxt = new System.Windows.Forms.RadioButton();
        this.txtWaterMarkFont = new System.Windows.Forms.TextBox();
        this.label = new System.Windows.Forms.Label();
        this.txtWaterMarkImg = new System.Windows.Forms.TextBox();
        this.label = new System.Windows.Forms.Label();
        this.btnSelect = new System.Windows.Forms.Button();
        this.pbImgPreview = new System.Windows.Forms.PictureBox();
        this.fontDialog = new System.Windows.Forms.FontDialog();
        this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
        this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
        this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
        this.statusStrip.SuspendLayout();
        this.splitContainer.Panel1.SuspendLayout();
        this.splitContainer.Panel2.SuspendLayout();
        this.splitContainer.SuspendLayout();
        this.groupBox.SuspendLayout();
        this.groupBox.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this.trackBar)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.pbImgPreview)).BeginInit();
        this.SuspendLayout();
        // 
        // statusStrip
        // 
        this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.tsslStatus,
        this.tsslText});
        this.statusStrip.Location = new System.Drawing.Point(0, 368);
        this.statusStrip.Name = "statusStrip1";
        this.statusStrip.Size = new System.Drawing.Size(601, 22);
        this.statusStrip.TabIndex = 0;
        this.statusStrip.Text = "statusStrip1";
        // 
        // tsslStatus
        // 
        this.tsslStatus.Name = "tsslStatus";
        this.tsslStatus.Size = new System.Drawing.Size(, 17);
        this.tsslStatus.Text = "准备就绪";
        // 
        // tsslText
        // 
        this.tsslText.Name = "tsslText";
        this.tsslText.Size = new System.Drawing.Size(, 17);
        // 
        // splitContainer
        // 
        this.splitContainer.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
        this.splitContainer.IsSplitterFixed = true;
        this.splitContainer.Location = new System.Drawing.Point(0, 0);
        this.splitContainer.Name = "splitContainer1";
        // 
        // splitContainer.Panel1
        // 
        this.splitContainer.Panel1.Controls.Add(this.groupBox1);
        // 
        // splitContainer.Panel2
        // 
        this.splitContainer.Panel2.Controls.Add(this.button2);
        this.splitContainer.Panel2.Controls.Add(this.txtSavaPath);
        this.splitContainer.Panel2.Controls.Add(this.label5);
        this.splitContainer.Panel2.Controls.Add(this.btnPreview);
        this.splitContainer.Panel2.Controls.Add(this.btnExit);
        this.splitContainer.Panel2.Controls.Add(this.btnPerform);
        this.splitContainer.Panel2.Controls.Add(this.btnLoadImg);
        this.splitContainer.Panel2.Controls.Add(this.groupBox2);
        this.splitContainer.Size = new System.Drawing.Size(601, 368);
        this.splitContainer.SplitterDistance = 206;
        this.splitContainer.SplitterWidth = 2;
        this.splitContainer.TabIndex = 1;
        // 
        // groupBox
        // 
        this.groupBox.Controls.Add(this.lbImgList);
        this.groupBox.Location = new System.Drawing.Point(7, 2);
        this.groupBox.Name = "groupBox1";
        this.groupBox.Size = new System.Drawing.Size(189, 359);
        this.groupBox.TabIndex = 0;
        this.groupBox.TabStop = false;
        this.groupBox.Text = "加水印图片列表";
        // 
        // lbImgList
        // 
        this.lbImgList.FormattingEnabled = true;
        this.lbImgList.ItemHeight =;
        this.lbImgList.Location = new System.Drawing.Point(, 13);
        this.lbImgList.Name = "lbImgList";
        this.lbImgList.Size = new System.Drawing.Size(, 340);
        this.lbImgList.TabIndex =;
        this.lbImgList.SelectedIndexChanged += new System.EventHandler(this.lbImgList_SelectedIndexChanged);
        // 
        // button
        // 
        this.button.Location = new System.Drawing.Point(321, 291);
        this.button.Name = "button2";
        this.button.Size = new System.Drawing.Size(65, 23);
        this.button.TabIndex = 8;
        this.button.Text = "浏览...";
        this.button.UseVisualStyleBackColor = true;
        this.button.Click += new System.EventHandler(this.button2_Click);
        // 
        // txtSavaPath
        // 
        this.txtSavaPath.BackColor = System.Drawing.Color.White;
        this.txtSavaPath.Enabled = false;
        this.txtSavaPath.Location = new System.Drawing.Point(, 292);
        this.txtSavaPath.Name = "txtSavaPath";
        this.txtSavaPath.ReadOnly = true;
        this.txtSavaPath.Size = new System.Drawing.Size(, 21);
        this.txtSavaPath.TabIndex =;
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(13, 296);
        this.label.Name = "label5";
        this.label.Size = new System.Drawing.Size(65, 12);
        this.label.TabIndex = 6;
        this.label.Text = "保存位置:";
        // 
        // btnPreview
        // 
        this.btnPreview.Location = new System.Drawing.Point(, 327);
        this.btnPreview.Name = "btnPreview";
        this.btnPreview.Size = new System.Drawing.Size(, 23);
        this.btnPreview.TabIndex =;
        this.btnPreview.Text = "水印预览";
        this.btnPreview.UseVisualStyleBackColor = true;
        this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click);
        // 
        // btnExit
        // 
        this.btnExit.Location = new System.Drawing.Point(, 327);
        this.btnExit.Name = "btnExit";
        this.btnExit.Size = new System.Drawing.Size(, 23);
        this.btnExit.TabIndex =;
        this.btnExit.Text = "关闭退出";
        this.btnExit.UseVisualStyleBackColor = true;
        this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
        // 
        // btnPerform
        // 
        this.btnPerform.Location = new System.Drawing.Point(, 327);
        this.btnPerform.Name = "btnPerform";
        this.btnPerform.Size = new System.Drawing.Size(, 23);
        this.btnPerform.TabIndex =;
        this.btnPerform.Text = "开始执行";
        this.btnPerform.UseVisualStyleBackColor = true;
        this.btnPerform.Click += new System.EventHandler(this.btnPerform_Click);
        // 
        // btnLoadImg
        // 
        this.btnLoadImg.Location = new System.Drawing.Point(, 327);
        this.btnLoadImg.Name = "btnLoadImg";
        this.btnLoadImg.Size = new System.Drawing.Size(, 23);
        this.btnLoadImg.TabIndex =;
        this.btnLoadImg.Text = "加载图片";
        this.btnLoadImg.UseVisualStyleBackColor = true;
        this.btnLoadImg.Click += new System.EventHandler(this.btnLoadImg_Click);
        // 
        // groupBox
        // 
        this.groupBox.Controls.Add(this.label6);
        this.groupBox.Controls.Add(this.label4);
        this.groupBox.Controls.Add(this.cbbPosition);
        this.groupBox.Controls.Add(this.label2);
        this.groupBox.Controls.Add(this.button1);
        this.groupBox.Controls.Add(this.trackBar1);
        this.groupBox.Controls.Add(this.rbPIC);
        this.groupBox.Controls.Add(this.rbTxt);
        this.groupBox.Controls.Add(this.txtWaterMarkFont);
        this.groupBox.Controls.Add(this.label1);
        this.groupBox.Controls.Add(this.txtWaterMarkImg);
        this.groupBox.Controls.Add(this.label3);
        this.groupBox.Controls.Add(this.btnSelect);
        this.groupBox.Controls.Add(this.pbImgPreview);
        this.groupBox.Location = new System.Drawing.Point(3, 3);
        this.groupBox.Name = "groupBox2";
        this.groupBox.Size = new System.Drawing.Size(383, 274);
        this.groupBox.TabIndex = 0;
        this.groupBox.TabStop = false;
        this.groupBox.Text = "水印设置";
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(10, 171);
        this.label.Name = "label6";
        this.label.Size = new System.Drawing.Size(257, 12);
        this.label.TabIndex = 16;
        this.label.Text = "注意:水印图片建议使用分辨率为368*75的图片";
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(244, 145);
        this.label.Name = "label4";
        this.label.Size = new System.Drawing.Size(65, 12);
        this.label.TabIndex = 4;
        this.label.Text = "水印位置:";
        // 
        // cbbPosition
        // 
        this.cbbPosition.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.cbbPosition.FormattingEnabled = true;
        this.cbbPosition.Items.AddRange(new object[] {
        "正中",
        "左上",
        "左下",
        "右上",
        "右下"});
        this.cbbPosition.Location = new System.Drawing.Point(, 141);
        this.cbbPosition.Name = "cbbPosition";
        this.cbbPosition.Size = new System.Drawing.Size(, 20);
        this.cbbPosition.TabIndex =;
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(8, 147);
        this.label.Name = "label2";
        this.label.Size = new System.Drawing.Size(65, 12);
        this.label.TabIndex = 14;
        this.label.Text = "透明设置:";
        // 
        // button
        // 
        this.button.Location = new System.Drawing.Point(315, 48);
        this.button.Name = "button1";
        this.button.Size = new System.Drawing.Size(65, 23);
        this.button.TabIndex = 13;
        this.button.Text = "字体设置";
        this.button.UseVisualStyleBackColor = true;
        this.button.Click += new System.EventHandler(this.button1_Click);
        // 
        // trackBar
        // 
        this.trackBar.AutoSize = false;
        this.trackBar.Enabled = false;
        this.trackBar.LargeChange = 1;
        this.trackBar.Location = new System.Drawing.Point(69, 140);
        this.trackBar.Maximum = 255;
        this.trackBar.Name = "trackBar1";
        this.trackBar.Size = new System.Drawing.Size(179, 22);
        this.trackBar.TabIndex = 12;
        this.trackBar.Value = 255;
        this.trackBar.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
        this.trackBar.Enter += new System.EventHandler(this.trackBar1_Enter);
        // 
        // rbPIC
        // 
        this.rbPIC.AutoSize = true;
        this.rbPIC.Location = new System.Drawing.Point(, 82);
        this.rbPIC.Name = "rbPIC";
        this.rbPIC.Size = new System.Drawing.Size(, 16);
        this.rbPIC.TabIndex =;
        this.rbPIC.Text = "添加图片水印";
        this.rbPIC.UseVisualStyleBackColor = true;
        this.rbPIC.CheckedChanged += new System.EventHandler(this.rbPIC_CheckedChanged);
        // 
        // rbTxt
        // 
        this.rbTxt.AutoSize = true;
        this.rbTxt.Checked = true;
        this.rbTxt.Location = new System.Drawing.Point(, 22);
        this.rbTxt.Name = "rbTxt";
        this.rbTxt.Size = new System.Drawing.Size(, 16);
        this.rbTxt.TabIndex =;
        this.rbTxt.TabStop = true;
        this.rbTxt.Text = "添加文字水印";
        this.rbTxt.UseVisualStyleBackColor = true;
        this.rbTxt.CheckedChanged += new System.EventHandler(this.rbTxt_CheckedChanged);
        // 
        // txtWaterMarkFont
        // 
        this.txtWaterMarkFont.Location = new System.Drawing.Point(, 49);
        this.txtWaterMarkFont.Name = "txtWaterMarkFont";
        this.txtWaterMarkFont.Size = new System.Drawing.Size(, 21);
        this.txtWaterMarkFont.TabIndex =;
        this.txtWaterMarkFont.TextChanged += new System.EventHandler(this.txtWaterMarkFont_TextChanged);
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(8, 53);
        this.label.Name = "label1";
        this.label.Size = new System.Drawing.Size(65, 12);
        this.label.TabIndex = 1;
        this.label.Text = "水印文字:";
        // 
        // txtWaterMarkImg
        // 
        this.txtWaterMarkImg.BackColor = System.Drawing.Color.White;
        this.txtWaterMarkImg.Enabled = false;
        this.txtWaterMarkImg.Location = new System.Drawing.Point(, 109);
        this.txtWaterMarkImg.Name = "txtWaterMarkImg";
        this.txtWaterMarkImg.ReadOnly = true;
        this.txtWaterMarkImg.Size = new System.Drawing.Size(, 21);
        this.txtWaterMarkImg.TabIndex =;
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(8, 114);
        this.label.Name = "label3";
        this.label.Size = new System.Drawing.Size(65, 12);
        this.label.TabIndex = 0;
        this.label.Text = "水印图片:";
        // 
        // btnSelect
        // 
        this.btnSelect.Location = new System.Drawing.Point(, 108);
        this.btnSelect.Name = "btnSelect";
        this.btnSelect.Size = new System.Drawing.Size(, 23);
        this.btnSelect.TabIndex =;
        this.btnSelect.Text = "浏览...";
        this.btnSelect.UseVisualStyleBackColor = true;
        this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click);
        // 
        // pbImgPreview
        // 
        this.pbImgPreview.BackColor = System.Drawing.Color.WhiteSmoke;
        this.pbImgPreview.BorderStyle = System.Windows.Forms.BorderStyle.FixedD;
        this.pbImgPreview.Location = new System.Drawing.Point(, 191);
        this.pbImgPreview.Name = "pbImgPreview";
        this.pbImgPreview.Size = new System.Drawing.Size(, 75);
        this.pbImgPreview.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
        this.pbImgPreview.TabIndex =;
        this.pbImgPreview.TabStop = false;
        // 
        // openFileDialog
        // 
        this.openFileDialog.Filter = "图片文件|*.jpeg;*.jpg;*.png;*.bmp;*.gif";
        this.openFileDialog.Multiselect = true;
        // 
        // openFileDialog
        // 
        this.openFileDialog.Filter = "图片文件|*.jpeg;*.jpg;*.png;*.bmp";
        // 
        // Form
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(, 390);
        this.Controls.Add(this.splitContainer);
        this.Controls.Add(this.statusStrip);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Name = "Form";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "图片批量加水印";
        this.Load += new System.EventHandler(this.Form_Load);
        this.statusStrip.ResumeLayout(false);
        this.statusStrip.PerformLayout();
        this.splitContainer.Panel1.ResumeLayout(false);
        this.splitContainer.Panel2.ResumeLayout(false);
        this.splitContainer.Panel2.PerformLayout();
        this.splitContainer.ResumeLayout(false);
        this.groupBox.ResumeLayout(false);
        this.groupBox.ResumeLayout(false);
        this.groupBox.PerformLayout();
        ((System.ComponentModel.ISupportInitialize)(this.trackBar)).EndInit();
        ((System.ComponentModel.ISupportInitialize)(this.pbImgPreview)).EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.ColorDialog colorDialog;
    private System.Windows.Forms.StatusStrip statusStrip;
    private System.Windows.Forms.SplitContainer splitContainer;
    private System.Windows.Forms.GroupBox groupBox;
    private System.Windows.Forms.ListBox lbImgList;
    private System.Windows.Forms.GroupBox groupBox;
    private System.Windows.Forms.TextBox txtWaterMarkFont;
    private System.Windows.Forms.Label label;
    private System.Windows.Forms.FontDialog fontDialog;
    private System.Windows.Forms.Button btnSelect;
    private System.Windows.Forms.TextBox txtWaterMarkImg;
    private System.Windows.Forms.Label label;
    private System.Windows.Forms.PictureBox pbImgPreview;
    private System.Windows.Forms.Label label;
    private System.Windows.Forms.Button btnLoadImg;
    private System.Windows.Forms.Button btnPreview;
    private System.Windows.Forms.Button btnExit;
    private System.Windows.Forms.Button btnPerform;
    private System.Windows.Forms.RadioButton rbPIC;
    private System.Windows.Forms.RadioButton rbTxt;
    private System.Windows.Forms.OpenFileDialog openFileDialog;
    private System.Windows.Forms.ToolStripStatusLabel tsslStatus;
    private System.Windows.Forms.ToolStripStatusLabel tsslText;
    private System.Windows.Forms.TrackBar trackBar;
    private System.Windows.Forms.OpenFileDialog openFileDialog;
    private System.Windows.Forms.Button button;
    private System.Windows.Forms.Label label;
    private System.Windows.Forms.ComboBox cbbPosition;
    private System.Windows.Forms.Button button;
    private System.Windows.Forms.TextBox txtSavaPath;
    private System.Windows.Forms.Label label;
    private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
    private System.Windows.Forms.Label label;
}
public partial class Form : Form
{
    public Form()
    {
        InitializeComponent();
    }
    public Image ig = null;
    private void Form_Load(object sender, EventArgs e)
    {
        pictureBox.Image = ig;
    }
}
partial class Form
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.pictureBox = new System.Windows.Forms.PictureBox();
        ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
        this.SuspendLayout();
        // 
        // pictureBox
        // 
        this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
        this.pictureBox.Location = new System.Drawing.Point(0, 0);
        this.pictureBox.Name = "pictureBox1";
        this.pictureBox.Size = new System.Drawing.Size(630, 448);
        this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
        this.pictureBox.TabIndex = 0;
        this.pictureBox.TabStop = false;
        // 
        // Form
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(, 448);
        this.Controls.Add(this.pictureBox);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Name = "Form";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "水印预览";
        this.Load += new System.EventHandler(this.Form_Load);
        ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.PictureBox pictureBox;
}