diff --git a/Electrical Weathering/Form1.Designer.cs b/Electrical Weathering/Form1.Designer.cs index 1137406..d1fcc3f 100644 --- a/Electrical Weathering/Form1.Designer.cs +++ b/Electrical Weathering/Form1.Designer.cs @@ -47,10 +47,21 @@ private void InitializeComponent() this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.label3 = new System.Windows.Forms.Label(); + this.zooming = new System.Windows.Forms.TrackBar(); + this.zoomingValue = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.Default_L = new System.Windows.Forms.RadioButton(); + this.Default_M = new System.Windows.Forms.RadioButton(); + this.Default_H = new System.Windows.Forms.RadioButton(); + this.Customized = new System.Windows.Forms.RadioButton(); + this.label4 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Compressing)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Greening)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Noise)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.zooming)).BeginInit(); + this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // pictureBox @@ -63,11 +74,12 @@ private void InitializeComponent() this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; this.pictureBox.TabIndex = 0; this.pictureBox.TabStop = false; + this.pictureBox.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox_Paint); // // Source // this.Source.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.Source.Location = new System.Drawing.Point(614, 85); + this.Source.Location = new System.Drawing.Point(614, 49); this.Source.Name = "Source"; this.Source.ReadOnly = true; this.Source.Size = new System.Drawing.Size(305, 30); @@ -76,7 +88,7 @@ private void InitializeComponent() // // Select // - this.Select.Location = new System.Drawing.Point(925, 85); + this.Select.Location = new System.Drawing.Point(925, 49); this.Select.Name = "Select"; this.Select.Size = new System.Drawing.Size(94, 30); this.Select.TabIndex = 2; @@ -93,27 +105,30 @@ private void InitializeComponent() // this.Compressing.Cursor = System.Windows.Forms.Cursors.SizeWE; this.Compressing.Enabled = false; - this.Compressing.Location = new System.Drawing.Point(662, 340); + this.Compressing.Location = new System.Drawing.Point(666, 233); this.Compressing.Maximum = 100; this.Compressing.Name = "Compressing"; this.Compressing.Size = new System.Drawing.Size(328, 56); this.Compressing.TabIndex = 3; this.Compressing.TickFrequency = 20; this.Compressing.Scroll += new System.EventHandler(this.Weathering_Scroll); + this.Compressing.ValueChanged += new System.EventHandler(this.Compressing_ValueChanged); // // WeatheringValue // this.WeatheringValue.AutoSize = true; - this.WeatheringValue.Location = new System.Drawing.Point(996, 340); + this.WeatheringValue.Location = new System.Drawing.Point(1000, 233); this.WeatheringValue.Name = "WeatheringValue"; - this.WeatheringValue.Size = new System.Drawing.Size(23, 25); + this.WeatheringValue.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.WeatheringValue.Size = new System.Drawing.Size(41, 25); this.WeatheringValue.TabIndex = 4; - this.WeatheringValue.Text = "0"; + this.WeatheringValue.Text = "0%"; + this.WeatheringValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(609, 340); + this.label1.Location = new System.Drawing.Point(609, 233); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(52, 25); this.label1.TabIndex = 5; @@ -122,7 +137,7 @@ private void InitializeComponent() // lable2 // this.lable2.AutoSize = true; - this.lable2.Location = new System.Drawing.Point(609, 257); + this.lable2.Location = new System.Drawing.Point(609, 171); this.lable2.Name = "lable2"; this.lable2.Size = new System.Drawing.Size(52, 25); this.lable2.TabIndex = 5; @@ -132,27 +147,30 @@ private void InitializeComponent() // this.Greening.Cursor = System.Windows.Forms.Cursors.SizeWE; this.Greening.Enabled = false; - this.Greening.Location = new System.Drawing.Point(662, 257); + this.Greening.Location = new System.Drawing.Point(666, 171); this.Greening.Maximum = 100; this.Greening.Name = "Greening"; this.Greening.Size = new System.Drawing.Size(328, 56); this.Greening.TabIndex = 3; this.Greening.TickFrequency = 20; this.Greening.Scroll += new System.EventHandler(this.Greening_Scroll); + this.Greening.ValueChanged += new System.EventHandler(this.Greening_ValueChanged); // // GreeningValue // this.GreeningValue.AutoSize = true; - this.GreeningValue.Location = new System.Drawing.Point(996, 257); + this.GreeningValue.Location = new System.Drawing.Point(1000, 171); this.GreeningValue.Name = "GreeningValue"; - this.GreeningValue.Size = new System.Drawing.Size(23, 25); + this.GreeningValue.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.GreeningValue.Size = new System.Drawing.Size(41, 25); this.GreeningValue.TabIndex = 4; - this.GreeningValue.Text = "0"; + this.GreeningValue.Text = "0%"; + this.GreeningValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Generate // this.Generate.Enabled = false; - this.Generate.Location = new System.Drawing.Point(900, 402); + this.Generate.Location = new System.Drawing.Point(939, 367); this.Generate.Name = "Generate"; this.Generate.Size = new System.Drawing.Size(119, 42); this.Generate.TabIndex = 2; @@ -163,7 +181,7 @@ private void InitializeComponent() // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(609, 175); + this.label2.Location = new System.Drawing.Point(609, 109); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(52, 25); this.label2.TabIndex = 5; @@ -173,27 +191,30 @@ private void InitializeComponent() // this.Noise.Cursor = System.Windows.Forms.Cursors.SizeWE; this.Noise.Enabled = false; - this.Noise.Location = new System.Drawing.Point(662, 175); + this.Noise.Location = new System.Drawing.Point(666, 109); this.Noise.Maximum = 100; this.Noise.Name = "Noise"; this.Noise.Size = new System.Drawing.Size(328, 56); this.Noise.TabIndex = 3; this.Noise.TickFrequency = 20; this.Noise.Scroll += new System.EventHandler(this.Noise_Scroll); + this.Noise.ValueChanged += new System.EventHandler(this.Noise_ValueChanged); // // noiseValue // this.noiseValue.AutoSize = true; - this.noiseValue.Location = new System.Drawing.Point(996, 175); + this.noiseValue.Location = new System.Drawing.Point(1000, 109); this.noiseValue.Name = "noiseValue"; - this.noiseValue.Size = new System.Drawing.Size(23, 25); + this.noiseValue.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.noiseValue.Size = new System.Drawing.Size(41, 25); this.noiseValue.TabIndex = 4; - this.noiseValue.Text = "0"; + this.noiseValue.Text = "0%"; + this.noiseValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // SaveBtn // this.SaveBtn.Enabled = false; - this.SaveBtn.Location = new System.Drawing.Point(900, 480); + this.SaveBtn.Location = new System.Drawing.Point(939, 482); this.SaveBtn.Name = "SaveBtn"; this.SaveBtn.Size = new System.Drawing.Size(119, 42); this.SaveBtn.TabIndex = 2; @@ -223,21 +244,130 @@ private void InitializeComponent() this.label3.Size = new System.Drawing.Size(2, 550); this.label3.TabIndex = 7; // + // zooming + // + this.zooming.Cursor = System.Windows.Forms.Cursors.SizeWE; + this.zooming.Enabled = false; + this.zooming.Location = new System.Drawing.Point(666, 295); + this.zooming.Maximum = 100; + this.zooming.Name = "zooming"; + this.zooming.Size = new System.Drawing.Size(328, 56); + this.zooming.TabIndex = 3; + this.zooming.TickFrequency = 20; + this.zooming.Value = 100; + this.zooming.Scroll += new System.EventHandler(this.zooming_Scroll); + // + // zoomingValue + // + this.zoomingValue.AutoSize = true; + this.zoomingValue.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.zoomingValue.Location = new System.Drawing.Point(1000, 295); + this.zoomingValue.Name = "zoomingValue"; + this.zoomingValue.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.zoomingValue.Size = new System.Drawing.Size(63, 25); + this.zoomingValue.TabIndex = 4; + this.zoomingValue.Text = "100%"; + this.zoomingValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(609, 295); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(52, 25); + this.label5.TabIndex = 5; + this.label5.Text = "缩放"; + // + // groupBox1 + // + this.groupBox1.BackColor = System.Drawing.SystemColors.Control; + this.groupBox1.Controls.Add(this.Customized); + this.groupBox1.Controls.Add(this.Default_H); + this.groupBox1.Controls.Add(this.Default_M); + this.groupBox1.Controls.Add(this.Default_L); + this.groupBox1.Enabled = false; + this.groupBox1.Location = new System.Drawing.Point(666, 357); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(192, 167); + this.groupBox1.TabIndex = 8; + this.groupBox1.TabStop = false; + // + // Default_L + // + this.Default_L.AutoSize = true; + this.Default_L.Location = new System.Drawing.Point(9, 24); + this.Default_L.Name = "Default_L"; + this.Default_L.Size = new System.Drawing.Size(153, 29); + this.Default_L.TabIndex = 0; + this.Default_L.TabStop = true; + this.Default_L.Text = "景泰蓝(低)"; + this.Default_L.UseVisualStyleBackColor = true; + this.Default_L.Click += new System.EventHandler(this.Default_L_Click); + // + // Default_M + // + this.Default_M.AutoSize = true; + this.Default_M.Location = new System.Drawing.Point(9, 59); + this.Default_M.Name = "Default_M"; + this.Default_M.Size = new System.Drawing.Size(153, 29); + this.Default_M.TabIndex = 1; + this.Default_M.TabStop = true; + this.Default_M.Text = "元青花(中)"; + this.Default_M.UseVisualStyleBackColor = true; + this.Default_M.Click += new System.EventHandler(this.Default_M_Click); + // + // Default_H + // + this.Default_H.AutoSize = true; + this.Default_H.Location = new System.Drawing.Point(9, 94); + this.Default_H.Name = "Default_H"; + this.Default_H.Size = new System.Drawing.Size(153, 29); + this.Default_H.TabIndex = 2; + this.Default_H.TabStop = true; + this.Default_H.Text = "唐三彩(高)"; + this.Default_H.UseVisualStyleBackColor = true; + this.Default_H.Click += new System.EventHandler(this.Default_H_Click); + // + // Customized + // + this.Customized.AutoSize = true; + this.Customized.Location = new System.Drawing.Point(9, 129); + this.Customized.Name = "Customized"; + this.Customized.Size = new System.Drawing.Size(93, 29); + this.Customized.TabIndex = 3; + this.Customized.TabStop = true; + this.Customized.Text = "自定义"; + this.Customized.UseVisualStyleBackColor = true; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(609, 367); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(52, 25); + this.label4.TabIndex = 5; + this.label4.Text = "预设"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1099, 609); + this.Controls.Add(this.groupBox1); this.Controls.Add(this.label3); this.Controls.Add(this.linkLabel1); this.Controls.Add(this.label2); this.Controls.Add(this.lable2); + this.Controls.Add(this.label4); + this.Controls.Add(this.label5); this.Controls.Add(this.label1); this.Controls.Add(this.noiseValue); this.Controls.Add(this.GreeningValue); + this.Controls.Add(this.zoomingValue); this.Controls.Add(this.WeatheringValue); this.Controls.Add(this.Noise); this.Controls.Add(this.Greening); + this.Controls.Add(this.zooming); this.Controls.Add(this.Compressing); this.Controls.Add(this.SaveBtn); this.Controls.Add(this.Generate); @@ -257,6 +387,9 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.Compressing)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Greening)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Noise)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.zooming)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -281,6 +414,15 @@ private void InitializeComponent() private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.LinkLabel linkLabel1; private System.Windows.Forms.Label label3; + private System.Windows.Forms.TrackBar zooming; + private System.Windows.Forms.Label zoomingValue; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.RadioButton Customized; + private System.Windows.Forms.RadioButton Default_H; + private System.Windows.Forms.RadioButton Default_M; + private System.Windows.Forms.RadioButton Default_L; + private System.Windows.Forms.Label label4; } } diff --git a/Electrical Weathering/Form1.cs b/Electrical Weathering/Form1.cs index a2b0b0c..58665a1 100644 --- a/Electrical Weathering/Form1.cs +++ b/Electrical Weathering/Form1.cs @@ -50,7 +50,9 @@ private void Select_Click(object sender, EventArgs e) Compressing.Enabled = true; Greening.Enabled = true; Noise.Enabled = true; + zooming.Enabled = true; Generate.Enabled = true; + groupBox1.Enabled = true; } } catch @@ -62,12 +64,22 @@ private void Select_Click(object sender, EventArgs e) private void Weathering_Scroll(object sender, EventArgs e) { - WeatheringValue.Text = Convert.ToString(Compressing.Value); + Customized.Checked = true; } private void Greening_Scroll(object sender, EventArgs e) { - GreeningValue.Text = Convert.ToString(Greening.Value); + Customized.Checked = true; + } + private void Noise_Scroll(object sender, EventArgs e) + { + Customized.Checked = true; + } + + private void zooming_Scroll(object sender, EventArgs e) + { + zoomingValue.Text = Convert.ToString(zooming.Value) + @"%"; + Customized.Checked = true; } private void Weatherizing_Click(object sender, EventArgs e) @@ -78,6 +90,7 @@ private void Weatherizing_Click(object sender, EventArgs e) pictureBox.Image = Handler.Noising(Emojpg, Noise.Value); pictureBox.Image = Handler.Greening(pictureBox.Image, Greening.Value); pictureBox.Image = Handler.Weathering(pictureBox.Image, Compressing.Value); + pictureBox.Image = Handler.Zooming(pictureBox.Image, zooming.Value/100f); SaveBtn.Enabled = true; } catch @@ -88,26 +101,28 @@ private void Weatherizing_Click(object sender, EventArgs e) } - private void Noise_Scroll(object sender, EventArgs e) - { - noiseValue.Text = Convert.ToString(Noise.Value); - } - private void SaveBtn_Click(object sender, EventArgs e) { - if (saveFileDialog1.ShowDialog() == DialogResult.OK) + try { - ImageCodecInfo myImageCodecInfo = Handler.GetEncoderInfo("image/jpeg"); - EncoderParameters myEncoderParameters = new EncoderParameters(1); - myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,100L); - using (Bitmap bitmap = new Bitmap(pictureBox.Image)) + if (saveFileDialog1.ShowDialog() == DialogResult.OK) { - using (MemoryStream ms = new MemoryStream()) + ImageCodecInfo myImageCodecInfo = Handler.GetEncoderInfo("image/jpeg"); + EncoderParameters myEncoderParameters = new EncoderParameters(1); + myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); + using (Bitmap bitmap = new Bitmap(pictureBox.Image)) { - bitmap.Save(saveFileDialog1.FileName, myImageCodecInfo, myEncoderParameters); + using (MemoryStream ms = new MemoryStream()) + { + bitmap.Save(saveFileDialog1.FileName, myImageCodecInfo, myEncoderParameters); + } } } } + catch + { + MessageBox.Show("就你那破图还想电子包浆?", "Excuse me?", MessageBoxButtons.OK); + } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -121,5 +136,61 @@ private void Source_TextChanged(object sender, EventArgs e) Source.Select(Source.TextLength, 0); Source.ScrollToCaret(); } + + private void pictureBox_Paint(object sender, PaintEventArgs e) + { + try + { + if (pictureBox.Image.Height > pictureBox.Height || pictureBox.Image.Width > pictureBox.Width) + { + pictureBox.SizeMode = PictureBoxSizeMode.Zoom; + } + else + { + pictureBox.SizeMode = PictureBoxSizeMode.CenterImage; + } + } + catch + { + + } + + } + + private void Default_L_Click(object sender, EventArgs e) + { + Noise.Value = 0; + Greening.Value = 5; + Compressing.Value = 80; + } + + private void Default_M_Click(object sender, EventArgs e) + { + Noise.Value = 5; + Greening.Value = 10; + Compressing.Value = 85; + } + + private void Default_H_Click(object sender, EventArgs e) + { + Noise.Value = 10; + Greening.Value = 15; + Compressing.Value = 90; + } + + private void Noise_ValueChanged(object sender, EventArgs e) + { + noiseValue.Text = Convert.ToString(Noise.Value) + @"%"; + } + + private void Greening_ValueChanged(object sender, EventArgs e) + { + GreeningValue.Text = Convert.ToString(Greening.Value) + @"%"; + } + + private void Compressing_ValueChanged(object sender, EventArgs e) + { + WeatheringValue.Text = Convert.ToString(Compressing.Value) + @"%"; + } } } diff --git a/Electrical Weathering/Handler.cs b/Electrical Weathering/Handler.cs index 012d3c3..c86be0e 100644 --- a/Electrical Weathering/Handler.cs +++ b/Electrical Weathering/Handler.cs @@ -51,7 +51,12 @@ static public Image Greening(Image Source,int alpha) for (y = 0; y < background.Height; y++) { Color sourceColor = background.GetPixel(x, y); - Color mixColor = Color.FromArgb(255,sourceColor.R * (100 - alpha) / 100,(sourceColor.G * (100-alpha) / 100)+255*alpha/100, sourceColor.B * (100 - alpha) / 100); + Color mixColor = Color.FromArgb( + 255, + sourceColor.R * (100 - alpha) / 100, + sourceColor.G * (100 - alpha) / 100 + 255 * alpha / 100, + sourceColor.B * (100 - alpha) / 100 + ); Mix.SetPixel(x, y, mixColor); } } @@ -72,12 +77,28 @@ static public Image Noising(Image Source, int alpha) for (y = 0; y < background.Height; y++) { Color sourceColor = background.GetPixel(x, y); - Color mixColor = Color.FromArgb(255, sourceColor.R * (100 - alpha) / 100+ rnd.Next(255) * alpha / 100, (sourceColor.G * (100 - alpha) / 100) + rnd.Next(255) * alpha / 100, sourceColor.B * (100 - alpha) / 100+rnd.Next(255) * alpha / 100); + Color mixColor = Color.FromArgb( + 255, + sourceColor.R * (100 - alpha) / 100 + rnd.Next(255) * alpha / 100, + sourceColor.G * (100 - alpha) / 100 + rnd.Next(255) * alpha / 100, + sourceColor.B * (100 - alpha) / 100 + rnd.Next(255) * alpha / 100 + ); Mix.SetPixel(x, y, mixColor); } } return Mix; } + + static public Image Zooming(Image Source, float Aspect) + { + + Bitmap result = new Bitmap((int)(Source.Width*Aspect), (int)(Source.Height * Aspect)); + using (Graphics g = Graphics.FromImage(result)) + { + g.DrawImage(Source, 0, 0, result.Width, result.Height); + } + return result; + } } }