using System;
using System.Drawing;
using System.Windows.Forms;
using PaintDotNet.Base.SettingModel;
using System.Collections;
using System.IO;
using PaintDotNet.Base.CommTool;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace PaintDotNet.Setting
{
public partial class WatermarkSettingsDialog : PdnBaseForm
{
#region 组件
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.RadioButton radioButton3;
private CustomControl.UserTextBox userTextBox2;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.RadioButton radioButton5;
private System.Windows.Forms.RadioButton radioButton6;
private System.Windows.Forms.RadioButton radioButton8;
private System.Windows.Forms.RadioButton radioButton7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.ComboBox comboBox3;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Button button5;
private CustomControl.UserTextBox userTextBox3;
//private System.Windows.Forms.ColorDialog colorVal;
private System.Windows.Forms.TextBox userTextBox1;
PaintDotNet.ColorsForm colorsForm;
private NumericUpDown numericUpDown1;
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeLanguageText()
{
this.groupBox2.Text = PdnResources.GetString("Menu.operation.text");
this.button4.Text = PdnResources.GetString("Menu.File.SaveAs.Text");
this.button3.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
this.label1.Text = PdnResources.GetString("Menu.Currentoperationstyle.text") + ":";
this.button2.Text = PdnResources.GetString("Menu.application.text");
this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
this.groupBox1.Text = PdnResources.GetString("Menu.Type.text");
this.radioButton2.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Imagewatermark.text");
this.radioButton1.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Textwatermark.text");
this.groupBox3.Text = PdnResources.GetString("Menu.Set.Watermarksettings.BasicInformation.text");
this.button5.Text = PdnResources.GetString("Menu.browse.Text");
this.radioButton3.Text = PdnResources.GetString("Menu.no.text");
this.radioButton4.Text = PdnResources.GetString("Menu.Yes.text");
this.label6.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Fromtheboundaryvalue.text") + ":";
this.label5.Text = PdnResources.GetString("Menu.transparency.text") + ":";
this.label4.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Tilewatermark.text") + ":";
this.label3.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Watermarkposition.text") + ":";
this.label2.Text = PdnResources.GetString("Menu.LabelAction.DrawWaterMark.Text") + ":";
this.groupBox4.Text = PdnResources.GetString("Menu.Set.Watermarksettings.ExtendInformation.text");
this.checkBox2.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Italic.text");
this.checkBox1.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Bold.text");
this.label10.Text = PdnResources.GetString("Menu.color.text") + ":";
this.label9.Text = PdnResources.GetString("Menu.Fontsize.text") + ":";
this.label8.Text = PdnResources.GetString("Menu.Font.text") + ":";
this.radioButton8.Text = PdnResources.GetString("Menu.Set.Watermarksettings.backwardlean.text");
this.radioButton7.Text = PdnResources.GetString("Menu.Verticaldirection.text");
this.label7.Text = PdnResources.GetString("Menu.direction.text") + ":";
this.radioButton5.Text = PdnResources.GetString("Menu.Set.Watermarksettings.battering.text");
this.radioButton6.Text = PdnResources.GetString("Menu.horizontaldirection.text");
this.groupBox5.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Watermarkpreview.text");
this.Text = PdnResources.GetString("Menu.Setting.WatermarkSetting.Text");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.userTextBox1 = new System.Windows.Forms.TextBox();
this.userTextBox3 = new PaintDotNet.CustomControl.UserTextBox();
this.button5 = new System.Windows.Forms.Button();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.userTextBox2 = new PaintDotNet.CustomControl.UserTextBox();
this.radioButton4 = new System.Windows.Forms.RadioButton();
this.label6 = new System.Windows.Forms.Label();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.panel2 = new System.Windows.Forms.Panel();
this.label10 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.comboBox3 = new System.Windows.Forms.ComboBox();
this.label8 = new System.Windows.Forms.Label();
this.radioButton8 = new System.Windows.Forms.RadioButton();
this.radioButton7 = new System.Windows.Forms.RadioButton();
this.label7 = new System.Windows.Forms.Label();
this.radioButton5 = new System.Windows.Forms.RadioButton();
this.radioButton6 = new System.Windows.Forms.RadioButton();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.groupBox5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.SuspendLayout();
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Controls.Add(this.button3);
this.groupBox2.Controls.Add(this.comboBox1);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Controls.Add(this.button1);
this.groupBox2.Location = new System.Drawing.Point(13, 12);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(613, 58);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
//
// button4
//
this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button4.Location = new System.Drawing.Point(361, 21);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 11;
this.button4.Text = "另存为";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button3
//
this.button3.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button3.Location = new System.Drawing.Point(280, 21);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 10;
this.button3.Text = "删除";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(114, 23);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(135, 20);
this.comboBox1.TabIndex = 9;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(19, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(89, 12);
this.label1.TabIndex = 2;
this.label1.Text = "当前操作样式:";
//
// button2
//
this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button2.Location = new System.Drawing.Point(523, 21);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Text = "应用";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button1.Location = new System.Drawing.Point(442, 21);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "保存";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Location = new System.Drawing.Point(13, 76);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(613, 58);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "类型";
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Cursor = System.Windows.Forms.Cursors.Hand;
this.radioButton2.Location = new System.Drawing.Point(284, 26);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(71, 16);
this.radioButton2.TabIndex = 5;
this.radioButton2.Text = "图片水印";
this.radioButton2.UseVisualStyleBackColor = true;
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Checked = true;
this.radioButton1.Cursor = System.Windows.Forms.Cursors.Hand;
this.radioButton1.Location = new System.Drawing.Point(19, 26);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(71, 16);
this.radioButton1.TabIndex = 4;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "文字水印";
this.radioButton1.UseVisualStyleBackColor = true;
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.userTextBox1);
this.groupBox3.Controls.Add(this.userTextBox3);
this.groupBox3.Controls.Add(this.button5);
this.groupBox3.Controls.Add(this.trackBar1);
this.groupBox3.Controls.Add(this.radioButton3);
this.groupBox3.Controls.Add(this.userTextBox2);
this.groupBox3.Controls.Add(this.radioButton4);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.comboBox2);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.label4);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.label2);
this.groupBox3.Location = new System.Drawing.Point(13, 140);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(613, 167);
this.groupBox3.TabIndex = 4;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "基本信息";
//
// userTextBox1
//
this.userTextBox1.Location = new System.Drawing.Point(90, 24);
this.userTextBox1.MaxLength = 50;
this.userTextBox1.Name = "userTextBox1";
this.userTextBox1.Size = new System.Drawing.Size(508, 21);
this.userTextBox1.TabIndex = 23;
this.userTextBox1.TextChanged += new System.EventHandler(this.userTextBox1_TextChanged_1);
//
// userTextBox3
//
this.userTextBox3.Location = new System.Drawing.Point(375, 122);
this.userTextBox3.Name = "userTextBox3";
this.userTextBox3.ReadOnly = true;
this.userTextBox3.Size = new System.Drawing.Size(46, 21);
this.userTextBox3.TabIndex = 22;
this.userTextBox3.Text = "0";
//
// button5
//
this.button5.Location = new System.Drawing.Point(523, 23);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 21;
this.button5.UseVisualStyleBackColor = true;
this.button5.Visible = false;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// trackBar1
//
this.trackBar1.Cursor = System.Windows.Forms.Cursors.Hand;
this.trackBar1.Location = new System.Drawing.Point(78, 116);
this.trackBar1.Maximum = 255;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(262, 45);
this.trackBar1.TabIndex = 1;
this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
//
// radioButton3
//
this.radioButton3.AutoSize = true;
this.radioButton3.Location = new System.Drawing.Point(186, 93);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Size = new System.Drawing.Size(35, 16);
this.radioButton3.TabIndex = 7;
this.radioButton3.Text = "否";
this.radioButton3.UseVisualStyleBackColor = true;
this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
//
// userTextBox2
//
this.userTextBox2.Location = new System.Drawing.Point(382, 58);
this.userTextBox2.MaxLength = 10;
this.userTextBox2.Name = "userTextBox2";
this.userTextBox2.Size = new System.Drawing.Size(216, 21);
this.userTextBox2.TabIndex = 20;
this.userTextBox2.TextChanged += new System.EventHandler(this.userTextBox2_TextChanged);
//
// radioButton4
//
this.radioButton4.AutoSize = true;
this.radioButton4.Checked = true;
this.radioButton4.Location = new System.Drawing.Point(90, 93);
this.radioButton4.Name = "radioButton4";
this.radioButton4.Size = new System.Drawing.Size(35, 16);
this.radioButton4.TabIndex = 6;
this.radioButton4.TabStop = true;
this.radioButton4.Text = "是";
this.radioButton4.UseVisualStyleBackColor = true;
this.radioButton4.CheckedChanged += new System.EventHandler(this.radioButton4_CheckedChanged);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(304, 61);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(65, 12);
this.label6.TabIndex = 19;
this.label6.Text = "距边界值:";
//
// comboBox2
//
this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox2.FormattingEnabled = true;
this.comboBox2.Location = new System.Drawing.Point(90, 58);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(197, 20);
this.comboBox2.TabIndex = 18;
this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(19, 125);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(53, 12);
this.label5.TabIndex = 17;
this.label5.Text = "透明度:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(19, 93);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(65, 12);
this.label4.TabIndex = 16;
this.label4.Text = "平铺水印:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(19, 61);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 15;
this.label3.Text = "水印位置:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(19, 29);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 12);
this.label2.TabIndex = 6;
this.label2.Text = "水印:";
//
// groupBox4
//
this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox4.Controls.Add(this.numericUpDown1);
this.groupBox4.Controls.Add(this.checkBox2);
this.groupBox4.Controls.Add(this.checkBox1);
this.groupBox4.Controls.Add(this.panel2);
this.groupBox4.Controls.Add(this.label10);
this.groupBox4.Controls.Add(this.label9);
this.groupBox4.Controls.Add(this.comboBox3);
this.groupBox4.Controls.Add(this.label8);
this.groupBox4.Controls.Add(this.radioButton8);
this.groupBox4.Controls.Add(this.radioButton7);
this.groupBox4.Controls.Add(this.label7);
this.groupBox4.Controls.Add(this.radioButton5);
this.groupBox4.Controls.Add(this.radioButton6);
this.groupBox4.Location = new System.Drawing.Point(13, 313);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(613, 118);
this.groupBox4.TabIndex = 5;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "扩展信息";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(375, 55);
this.numericUpDown1.Maximum = new decimal(new int[] {
49000,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(192, 21);
this.numericUpDown1.TabIndex = 26;
this.numericUpDown1.Value = new decimal(new int[] {
12,
0,
0,
0});
this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(347, 93);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(48, 16);
this.checkBox2.TabIndex = 25;
this.checkBox2.Text = "斜体";
this.checkBox2.UseVisualStyleBackColor = true;
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(284, 93);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(48, 16);
this.checkBox1.TabIndex = 24;
this.checkBox1.Text = "粗体";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Transparent;
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel2.Location = new System.Drawing.Point(66, 88);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(191, 21);
this.panel2.TabIndex = 23;
this.panel2.Click += new System.EventHandler(this.panel2_Click);
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(19, 90);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(41, 12);
this.label10.TabIndex = 22;
this.label10.Text = "颜色:";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(322, 58);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(41, 12);
this.label9.TabIndex = 20;
this.label9.Text = "字号:";
//
// comboBox3
//
this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox3.FormattingEnabled = true;
this.comboBox3.Location = new System.Drawing.Point(66, 55);
this.comboBox3.Name = "comboBox3";
this.comboBox3.Size = new System.Drawing.Size(191, 20);
this.comboBox3.TabIndex = 19;
this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(19, 58);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(41, 12);
this.label8.TabIndex = 10;
this.label8.Text = "字体:";
//
// radioButton8
//
this.radioButton8.AutoSize = true;
this.radioButton8.Location = new System.Drawing.Point(333, 24);
this.radioButton8.Name = "radioButton8";
this.radioButton8.Size = new System.Drawing.Size(71, 16);
this.radioButton8.TabIndex = 9;
this.radioButton8.Text = "向后倾斜";
this.radioButton8.UseVisualStyleBackColor = true;
this.radioButton8.CheckedChanged += new System.EventHandler(this.radioButton8_CheckedChanged);
//
// radioButton7
//
this.radioButton7.AutoSize = true;
this.radioButton7.Location = new System.Drawing.Point(159, 24);
this.radioButton7.Name = "radioButton7";
this.radioButton7.Size = new System.Drawing.Size(71, 16);
this.radioButton7.TabIndex = 8;
this.radioButton7.Text = "垂直方向";
this.radioButton7.UseVisualStyleBackColor = true;
this.radioButton7.CheckedChanged += new System.EventHandler(this.radioButton7_CheckedChanged);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(19, 26);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(41, 12);
this.label7.TabIndex = 7;
this.label7.Text = "方向:";
//
// radioButton5
//
this.radioButton5.AutoSize = true;
this.radioButton5.Location = new System.Drawing.Point(245, 24);
this.radioButton5.Name = "radioButton5";
this.radioButton5.Size = new System.Drawing.Size(71, 16);
this.radioButton5.TabIndex = 5;
this.radioButton5.Text = "向前倾斜";
this.radioButton5.UseVisualStyleBackColor = true;
this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
//
// radioButton6
//
this.radioButton6.AutoSize = true;
this.radioButton6.Checked = true;
this.radioButton6.Location = new System.Drawing.Point(77, 24);
this.radioButton6.Name = "radioButton6";
this.radioButton6.Size = new System.Drawing.Size(71, 16);
this.radioButton6.TabIndex = 4;
this.radioButton6.TabStop = true;
this.radioButton6.Text = "水平方向";
this.radioButton6.UseVisualStyleBackColor = true;
this.radioButton6.CheckedChanged += new System.EventHandler(this.radioButton6_CheckedChanged);
//
// groupBox5
//
this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox5.Controls.Add(this.pictureBox2);
this.groupBox5.Location = new System.Drawing.Point(13, 437);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(613, 236);
this.groupBox5.TabIndex = 6;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "水印预览";
//
// pictureBox2
//
this.pictureBox2.Location = new System.Drawing.Point(6, 12);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(601, 218);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// WatermarkSettingsDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(637, 691);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "WatermarkSettingsDialog";
this.Text = "水印设置";
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.groupBox4, 0);
this.Controls.SetChildIndex(this.groupBox5, 0);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.groupBox5.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false);
}
private void InitializeColorForm()
{
this.colorsForm = new PaintDotNet.ColorsForm();
//
// colorsForm
//
this.colorsForm.AnalyzeSettingModel = null;
this.colorsForm.ClientSize = new System.Drawing.Size(209, 217);
this.colorsForm.EnableInstanceOpacity = true;
this.colorsForm.ForceActiveTitleBar = true;
this.colorsForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.colorsForm.KeyPreview = true;
this.colorsForm.Location = new System.Drawing.Point(0, 0);
this.colorsForm.MaximizeBox = false;
this.colorsForm.MinimizeBox = false;
this.colorsForm.Name = "colorsForm";
this.colorsForm.ShowInTaskbar = false;
this.colorsForm.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.colorsForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.colorsForm.Visible = false;
this.colorsForm.WhichUserColor = PaintDotNet.WhichUserColor.Primary;
this.colorsForm.Load += new System.EventHandler(this.colorsForm_Load);
}
private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
{
}
///
/// 画板点击
///
///
///
private void panel2_Click(object sender, EventArgs e)
{
this.colorsForm.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
this.colorsForm.setSaveBtn_Click(new System.EventHandler(this.panel2Changed));
this.colorsForm.ShowDialog();
}
private void panel2Changed(object sender, EventArgs e)
{
this.panel2.BackColor = this.colorsForm.UserPrimaryColor.ToColor();
this.watermarkModel.color = Convert.ToInt32(this.panel2.BackColor.ToArgb());
this.pictureBox2.Invalidate();
this.colorsForm.Close();
}
#endregion
#endregion
///
/// 另存为文件名
///
private string newName;
///
/// 操作样式下拉数据
///
private List files = new List();
private float localX = 0;
private float localY = 0;
private WatermarkModel watermarkModel = Startup.instance.watermarkModel;
///
/// 旋转角度
///
private int angle = 0;
///
/// 水印位置下拉选
///
string[] position = new string[]
{ PdnResources.GetString("Menu.Set.Watermarksettings.Topleft.text"),
PdnResources.GetString("Menu.Set.Watermarksettings.Topmiddle.text"),
PdnResources.GetString("Menu.Set.Watermarksettings.Topright.text"),
PdnResources.GetString("Menu.Set.Watermarksettings.Middleleft.text"),
PdnResources.GetString("Menu.nthemiddle.Text"),
PdnResources.GetString("Menu.Set.Watermarksettings.Middleright.text"),
PdnResources.GetString("Menu.Set.Watermarksettings.Bottomleft.text"),
PdnResources.GetString("Menu.Set.Watermarksettings.Bottommiddle.text"),
PdnResources.GetString("Menu.Set.Watermarksettings.Bottomright.text") };
///
/// 暂存文字水印信息
///
string waterMarkText = "";
///
/// 暂存图片水印路径
///
string waterMarkImagePath = "";
CreateNameDialog dialog;
public WatermarkSettingsDialog()
{
InitializeComponent();
InitializeLanguageText();
InitializeColorForm();
InitializeControl();
InitializeData();
}
///
/// 处理控件
///
private void InitializeControl()
{
this.pictureBox2.Paint += new PaintEventHandler(this.pictureBox2_Paint);
}
///
/// pictureBox的绘制事件
///
///
///
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
WatermarkModel model = new WatermarkModel();
model = watermarkModel;
if (this.checkBox1.Checked)
{
model.bold = 1;
}
else
{
model.bold = 2;
}
if (this.checkBox2.Checked)
{
model.italic = 1;
}
else
{
model.italic = 2;
}
model.position = this.comboBox2.SelectedIndex + 1;
model.typeface = this.comboBox3.Text;
model.fontSize = Int32.Parse(this.numericUpDown1.Value.ToString());
if (this.radioButton2.Checked)
{
//drawWatermarkImage(e.Graphics, model);
drawWatermarkImage(e.Graphics, model);
}
else
{
drawWatermarkText(e.Graphics, model);
}
}
///
/// 初始化数据
///
private void InitializeData()
{
//绑定字体下拉
ArrayList fontsItems = new ArrayList();
System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
foreach (FontFamily fontFamily in fonts.Families)
{
fontsItems.Add(fontFamily.Name);
}
this.comboBox3.DataSource = fontsItems;
//绑定位置下拉
this.comboBox2.DataSource = position;
//绑定样式下拉
InitializeStyleName();
}
///
/// 绑定样式下拉
///
private void InitializeStyleName()
{
List fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\");
files.Clear();
foreach (string fileName in fileNames)
{
string name = fileName.Substring(0, fileName.LastIndexOf("."));
files.Add(name);
}
this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged;
this.comboBox1.DataSource = null;
this.comboBox1.DataSource = files;
string nowModelName = Startup.instance.configModel.Watermark.Substring(0, Startup.instance.configModel.Watermark.LastIndexOf("."));
this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName));
watermarkModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
InitializeWaterData();
this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
}
///
/// 初始化控件的值
///
private void InitializeWaterData()
{
// 水印类型 1文字水印 2图片水印
if (this.watermarkModel.watermarkType == 2)
{
this.radioButton2.Checked = true;
}
else
{
this.radioButton1.Checked = true;
}
// 水印文字
this.userTextBox1.Text = this.watermarkModel.content;
//水印位置
this.comboBox2.SelectedIndex = this.watermarkModel.position - 1;
// 距边界值
this.userTextBox2.Text = this.watermarkModel.margin + "";
// 平铺水印
if (this.watermarkModel.spread == 2)
{
this.radioButton3.Checked = true;
}
else
{
this.radioButton4.Checked = true;
}
// 透明度
this.trackBar1.Value = this.watermarkModel.transparency;
this.userTextBox3.Text = this.watermarkModel.transparency + "";
// 方向
switch (this.watermarkModel.direction)
{
case 1:
this.radioButton6.Checked = true;
break;
case 2:
this.radioButton7.Checked = true;
break;
case 3:
this.radioButton5.Checked = true;
break;
case 4:
this.radioButton8.Checked = true;
break;
default:
this.radioButton6.Checked = true;
break;
}
//字体
this.comboBox3.Text = this.watermarkModel.typeface;
//字号
this.numericUpDown1.Value = this.watermarkModel.fontSize;
// 水印文字-颜色
this.panel2.BackColor = Color.FromArgb(this.watermarkModel.color);
// 粗体
if (this.watermarkModel.bold == 1)
{
this.checkBox1.Checked = true;
}
// 斜体
if (this.watermarkModel.italic == 1)
{
this.checkBox2.Checked = true;
}
this.pictureBox2.Invalidate();
//comboBox1_SelectedIndexChanged(null,null);
}
///
/// 当前操作样式
///
///
///
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
watermarkModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
InitializeWaterData();
}
///
/// 文字水印
///
///
///
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
waterMarkImagePath = this.userTextBox1.Text;
this.userTextBox1.Text = waterMarkText;
this.userTextBox1.ReadOnly = false;
this.watermarkModel.watermarkType = 1;
this.groupBox4.Visible = true; // 扩展信息
this.button5.Visible = false;
this.userTextBox1.Size = new Size(508, 21);
this.groupBox5.Location = new System.Drawing.Point(12, 437);
}
}
///
/// 图片水印
///
///
///
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
waterMarkText = this.userTextBox1.Text;
this.userTextBox1.Text = waterMarkImagePath;
this.userTextBox1.ReadOnly = true;
this.pictureBox2.Refresh();
this.watermarkModel.watermarkType = 2;
this.groupBox4.Visible = false; // 扩展信息
this.button5.Visible = true;
this.userTextBox1.Size = new Size(508 - 75, 21);
this.groupBox5.Location = new System.Drawing.Point(12, 313);
}
}
///
/// 基本信息-水印-水印文字
///
///
///
private void userTextBox1_TextChanged(object sender, EventArgs e)
{
}
///
/// 基本信息-水印-选择图片水印
///
///
///
private void button5_Click(object sender, EventArgs e)
{
var openFileDialog1 = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.userTextBox1.Text = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
this.watermarkModel.content = this.userTextBox1.Text;
Image image = Image.FromFile(openFileDialog1.FileName);
}
}
private void userTextBox1_TextChanged_1(object sender, EventArgs e)
{
if (this.watermarkModel.content == "")
{
this.watermarkModel.content = this.userTextBox1.Text;
}
this.pictureBox2.Invalidate();
}
///
/// 基本信息-透明度滑块
///
///
///
private void trackBar1_Scroll(object sender, EventArgs e)
{
this.userTextBox3.Text = "" + this.trackBar1.Value;
this.watermarkModel.transparency = this.trackBar1.Value;
this.pictureBox2.Invalidate();
}
///
/// 距边界值
///
///
///
private void userTextBox2_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.userTextBox2.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.edistancefromtheboundaryaluecanno.Text"));
return;
}
this.watermarkModel.margin = Int32.Parse(this.userTextBox2.Text);
this.pictureBox2.Invalidate();
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
this.watermarkModel.spread = 1;
this.pictureBox2.Invalidate();
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
this.watermarkModel.spread = 2;
this.pictureBox2.Invalidate();
}
///
/// 扩展信息-方向- 向前倾斜
///
///
///
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
this.angle = -45;
this.watermarkModel.direction = 3;
this.pictureBox2.Invalidate();
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
this.angle = 0;
this.watermarkModel.direction = 1;
this.pictureBox2.Invalidate();
}
private void radioButton7_CheckedChanged(object sender, EventArgs e)
{
this.angle = 90;
this.watermarkModel.direction = 2;
this.pictureBox2.Invalidate();
}
private void radioButton8_CheckedChanged(object sender, EventArgs e)
{
this.angle = 45;
this.watermarkModel.direction = 4;
this.pictureBox2.Invalidate();
}
///
/// 删除
///
///
///
private void button3_Click(object sender, EventArgs e)
{
if ("Default".Equals(this.comboBox1.Text))
{
MessageBox.Show(PdnResources.GetString("Menu.efaultstylecannotbedelete.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.nfirmthedeleti.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
if (dr == DialogResult.OK)
{
int newIndex = 0;
int selectIndex = this.comboBox1.SelectedIndex;
int tall = files.Count - 1;
if (selectIndex < tall)
{
newIndex = selectIndex;
}
string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.Text + ".xml";
FileInfo fileInfo = new FileInfo(filePath);
fileInfo.Delete();
InitializeStyleName();
this.comboBox1.SelectedIndex = newIndex;
watermarkModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
InitializeWaterData();
}
else if (dr == DialogResult.Cancel)
{
}
}
///
/// 另存为
///
///
///
private void button4_Click(object sender, EventArgs e)
{
dialog = new CreateNameDialog(this);
dialog.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Newstyle.text");
dialog.StartPosition = FormStartPosition.CenterParent;
dialog.ShowDialog();
}
///
/// 另存配置文件
///
private void CopyConfigAndRename()
{
if (this.checkBox1.Checked)
{
this.watermarkModel.bold = 1;
}
else
{
this.watermarkModel.bold = 2;
}
if (this.checkBox2.Checked)
{
this.watermarkModel.italic = 1;
}
else
{
this.watermarkModel.italic = 2;
}
this.watermarkModel.content = this.userTextBox1.Text;
this.watermarkModel.position = this.comboBox2.SelectedIndex + 1;
this.watermarkModel.typeface = this.comboBox3.Text;
this.watermarkModel.fontSize = Int32.Parse(this.numericUpDown1.Value.ToString());
string stageModelXml = XmlSerializeHelper.XmlSerialize(this.watermarkModel);
string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.newName + ".xml";
FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
}
///
/// 保存当前配置文件
///
///
///
private void button1_Click(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
{
this.watermarkModel.bold = 1;
}
else
{
this.watermarkModel.bold = 2;
}
if (this.checkBox2.Checked)
{
this.watermarkModel.italic = 1;
}
else
{
this.watermarkModel.italic = 2;
}
this.watermarkModel.content = this.userTextBox1.Text;
this.watermarkModel.position = this.comboBox2.SelectedIndex + 1;
this.watermarkModel.typeface = this.comboBox3.Text;
this.watermarkModel.fontSize = Int32.Parse(this.numericUpDown1.Value.ToString());
string stageModelXml = XmlSerializeHelper.XmlSerialize(this.watermarkModel);
string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.Text + ".xml";
FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
this.pictureBox2.Invalidate();
}
///
/// 应用当前的水印配置
///
///
///
private void button2_Click(object sender, EventArgs e)
{
Startup.instance.watermarkModel = this.watermarkModel;
Startup.instance.watermarkModel = this.watermarkModel;
}
public override void GetCreateName(string name)
{
this.newName = name;
if (files.Contains(this.newName))
{
MessageBox.Show(PdnResources.GetString("Menu.Stylenamecannotberepeated.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
CopyConfigAndRename();
InitializeStyleName();
dialog.Close();
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
this.pictureBox2.Invalidate();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
this.pictureBox2.Invalidate();
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
this.pictureBox2.Invalidate();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
this.pictureBox2.Invalidate();
}
///
/// 绘制水印-文字
///
/// 画布
/// 水印信息
public void drawWatermarkText(Graphics graphics, WatermarkModel model)
{
int width = this.pictureBox2.Width;
int height = this.pictureBox2.Height;
int padding = model.margin;
string text = model.content;
string fontVal = model.typeface; // 字体
int fontSize = model.fontSize * 2; // 字号
int transparency = model.transparency;// 透明度
Color color = Color.FromArgb(transparency, Color.FromArgb(model.color));// 颜色
Font font = new Font(fontVal, fontSize, GraphicsUnit.Pixel);
if (model.bold == 1)
{
font = new Font(fontVal, fontSize, FontStyle.Bold, GraphicsUnit.Pixel);//粗体
}
if (model.italic == 1)
{
font = new Font(fontVal, fontSize, FontStyle.Italic, GraphicsUnit.Pixel);//斜体
}
if (model.italic == 1 && model.bold == 1)
{
font = new Font(fontVal, fontSize, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Pixel);//加粗斜体
}
//获取可以用来绘制水印图片的有效区域
Rectangle validRect = new Rectangle(padding, padding, width - padding * 2, height - padding * 2);
if (model.spread == 2)
{
SizeF sf = graphics.MeasureString(text, font); //获取需要绘制的字符串大小
StringFormat format = GetStringFormat(model.position, sf.Width, sf.Height, this.pictureBox2.Width, this.pictureBox2.Height, model.margin); //获取绘画水印文字的格式,即文字对齐方式
Matrix mtxSave = graphics.Transform; //原始旋转矩阵
Matrix matrix = graphics.Transform;
matrix.RotateAt((float)angle, new PointF(localX + sf.Width / 2, localY + sf.Height / 2));
graphics.Transform = matrix;
graphics.DrawString(text, font, new SolidBrush(color), localX, localY);
graphics.Transform = mtxSave; //还原为原始旋转矩阵
//graphics.DrawString(text, font, new SolidBrush(color), validRect, format);
}
else if (model.spread == 1)
{
float textLength = font.Size * text.Length + 30;
float xpos = 0;
float ypos = 0;
// 倾斜
graphics.RotateTransform(this.angle);
// 循环打印文字水印
for (float i = -width / 2; i < width * 1.5; i = i + textLength)
{
xpos = i;
for (float j = -3 * height; j < height * 2.5; j += 50)
{
ypos = j;
graphics.DrawString(text, font, new SolidBrush(color), xpos, ypos);
}
}
}
}
///
/// 获取文字水印位置
///
///
/// 左顶,顶中,右顶,左中,居中,右中,左底,底中,右底
/// 1左上,2中上,3右上
/// 4左中,5中, 6右中
/// 7左下,8中下,9右下
///
///
public StringFormat GetStringFormat(int pos, float textwidth, float textheigth, int width, int heigth, int margin)
{
StringFormat format = new StringFormat();
switch (pos)
{
case 1:
format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near;
localX = margin;
localY = margin;
break;
case 2:
format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Near;
localX = (width - 2 * margin) / 2 - textwidth / 2;
localY = margin;
break;
case 3:
format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Near;
localX = (width - 2 * margin) - textwidth;
localY = margin;
break;
case 4:
format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center;
localX = margin;
localY = (heigth - 2 * margin) / 2 - textheigth / 2;
break;
case 5:
localX = (width - 2 * margin) / 2 - textwidth / 2;
localY = (heigth - 2 * margin) / 2 - textheigth / 2;
break;
case 6:
format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Center;
localX = (width - 2 * margin) - textwidth;
localY = (heigth - 2 * margin) / 2 - textheigth / 2;
break;
case 7:
format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Far;
localX = margin;
localY = (heigth - 2 * margin) - textheigth;
break;
case 8:
format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Far;
localX = (width - 2 * margin) / 2 - textwidth / 2;
localY = (heigth - 2 * margin) - textheigth;
break;
case 9:
format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Far;
localX = (width - 2 * margin) - textwidth;
localY = (heigth - 2 * margin) - textheigth;
break;
default:
format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center;
break;
}
return format;
}
///
/// 图片透明度属性
///
///
///
public ImageAttributes GetAlphaImgAttr(int opcity)
{
if (opcity < 0 || opcity > 255)
{
throw new ArgumentOutOfRangeException("opcity 值为 0~255");
}
//颜色矩阵
float[][] matrixItems =
{
new float[]{1,0,0,0,0},
new float[]{0,1,0,0,0},
new float[]{0,0,1,0,0},
new float[]{0,0,0,(float)opcity / 255, 0},
new float[]{0,0,0,0,1}
};
ColorMatrix colorMatrix = new ColorMatrix(matrixItems);
ImageAttributes imageAtt = new ImageAttributes();
imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
return imageAtt;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
this.pictureBox2.Invalidate();
}
///
/// 绘制水印-图片
///
/// 画布
/// 水印信息
public void drawWatermarkImage(Graphics graphics, WatermarkModel watermarkModel)
{
string waterPath = watermarkModel.content;
int position = watermarkModel.position; // 设置水印位置,1左上,2中上,3右上,4左中,5中, 6右中,7左下,8中下,9右下
int padding = watermarkModel.margin;
int opcity = watermarkModel.transparency;
Image waterImage = null;
if (string.IsNullOrEmpty(waterPath))
{
return;
}
try
{
waterImage = Image.FromFile(waterPath, false); //获取水印图片
}
catch (Exception)
{
return;
}
var waterRect = new Rectangle(0, 0, waterImage.Width, waterImage.Height);
if (opcity <= 0)
{
return;
}
Rectangle validRect = new Rectangle(padding, padding, this.pictureBox2.Width - padding * 2, this.pictureBox2.Height - padding * 2); //获取可以用来绘制水印图片的有效区域
ImageAttributes imageAtt = GetAlphaImgAttr(opcity);
Rectangle destRect = GetRectangleByPostion(validRect, waterRect, position); //计算水印图片的绘制位置
if (watermarkModel.spread == 2) // 非水印平铺
{
//Rectangle destRect = GetRectangleByPostion(validRect, waterRect, position); //计算水印图片的绘制位置
if (opcity == 255) //如果不透明度=100,那么直接将水印画到当前画布上.
{
graphics.DrawImage(waterImage, destRect, waterRect, GraphicsUnit.Pixel);
}
else //如果不透明度在0到255之间,设置透明参数
{
graphics.DrawImage(waterImage, destRect, 0, 0, waterRect.Width, waterRect.Height, GraphicsUnit.Pixel, imageAtt);//将水印图片画到画布上
}
}
else if (watermarkModel.spread == 1) // 水印平铺
{
int width = this.pictureBox2.Width;
int height = this.pictureBox2.Height;
float imageLength = waterImage.Width + 10;
float imageHeight = waterImage.Height + 10;
float xpos = 0;
float ypos = 0;
// 循环打印文字水印
for (float i = watermarkModel.margin; i <= width; i += imageLength)
{
xpos = i;
for (float j = watermarkModel.margin; j <= height; j += imageHeight)
{
ypos = j;
destRect.X = (int)xpos;
destRect.Y = (int)ypos;
graphics.DrawImage(waterImage, destRect, 0, 0, waterRect.Width, waterRect.Height, GraphicsUnit.Pixel, imageAtt);//将水印图片画到画布上
}
}
}
}
///
/// 获取图片水印位置,及small在big里的位置
/// 如果small的高度大于big的高度,返回big的高度
/// 如果small的宽度大于big的宽度,返回big的宽度
///
///
/// 1左上,2中上,3右上
/// 4左中,5中, 6右中
/// 7左下,8中下,9右下
///
///
public Rectangle GetRectangleByPostion(Rectangle big, Rectangle small, int pos)
{
if (big.Width < small.Width)
{
small.Width = big.Width;
}
if (big.Height < small.Height)
{
small.Height = big.Height;
}
Rectangle retVal = small;
switch (pos)
{
case 1: retVal.X = 0; retVal.Y = 0; break;
case 2: retVal.X = (big.Width - small.Width) / 2; retVal.Y = 0; break;
case 3: retVal.X = big.Width - small.Width; retVal.Y = 0; break;
case 4: retVal.X = 0; retVal.Y = (big.Height - small.Height) / 2; break;
case 6: retVal.X = big.Width - small.Width; retVal.Y = (big.Height - small.Height) / 2; break;
case 7: retVal.X = 0; retVal.Y = big.Height - small.Height; break;
case 8: retVal.X = (big.Width - small.Width) / 2; retVal.Y = big.Height - small.Height; break;
case 9: retVal.X = big.Width - small.Width; retVal.Y = big.Height - small.Height; break;
default: retVal.X = (big.Width - small.Width) / 2; retVal.Y = (big.Height - small.Height) / 2; break;
}
retVal.X += big.X;
retVal.Y += big.Y;
return retVal;
}
private void colorsForm_Load(object sender, EventArgs e)
{
}
}
}