C#-Imaging - Moire Fringe (摩尔纹)
Imaging.cs
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace CSharp_Imaging_Moire_Fringe
{
public sealed class Imaging
{
private static BitmapData _BitmapData = new BitmapData();
#region Moire_Fringe( Bitmap ObjectBitmap )
public static void Moire_Fringe( Bitmap ObjectBitmap )
{
try
{
if( ObjectBitmap == null )
{
return;
}
_BitmapData = ObjectBitmap.LockBits( new Rectangle( 0 , 0 , ObjectBitmap.Width , ObjectBitmap.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
unsafe
{
byte* P = (byte *)_BitmapData.Scan0;
for( int i = 0 ; i < _BitmapData.Height / 2 ; i++ )
{
for( int j = 0 ; j < _BitmapData.Width / 2 ; j++ )
{
P += 3;
P[2] = P[1] = P[0] = 0;
P += 3;
}
for( int k = 0 ; k < _BitmapData.Width / 2 ; k++ )
{
P[2] = P[1] = P[0] = 0;
P += 6;
}
}
}
}
catch( Exception E )
{
System.Windows.Forms.MessageBox.Show( E.ToString() );
}
finally
{
ObjectBitmap.UnlockBits( _BitmapData );
}
}
#endregion
}
}
using System.Drawing;
using System.Drawing.Imaging;
namespace CSharp_Imaging_Moire_Fringe
{
public sealed class Imaging
{
private static BitmapData _BitmapData = new BitmapData();
#region Moire_Fringe( Bitmap ObjectBitmap )
public static void Moire_Fringe( Bitmap ObjectBitmap )
{
try
{
if( ObjectBitmap == null )
{
return;
}
_BitmapData = ObjectBitmap.LockBits( new Rectangle( 0 , 0 , ObjectBitmap.Width , ObjectBitmap.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
unsafe
{
byte* P = (byte *)_BitmapData.Scan0;
for( int i = 0 ; i < _BitmapData.Height / 2 ; i++ )
{
for( int j = 0 ; j < _BitmapData.Width / 2 ; j++ )
{
P += 3;
P[2] = P[1] = P[0] = 0;
P += 3;
}
for( int k = 0 ; k < _BitmapData.Width / 2 ; k++ )
{
P[2] = P[1] = P[0] = 0;
P += 6;
}
}
}
}
catch( Exception E )
{
System.Windows.Forms.MessageBox.Show( E.ToString() );
}
finally
{
ObjectBitmap.UnlockBits( _BitmapData );
}
}
#endregion
}
}
Form1.cs
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace CSharp_Imaging_Moire_Fringe
{
public class Form1 : System.Windows.Forms.Form
{
#region Windows 窗体设计器生成的代码
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.ComponentModel.IContainer components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(44, 38);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(256, 256);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(332, 38);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(256, 256);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(632, 333);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "C# - Imaging - Moire Fringe";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
[STAThread]
private static void Main()
{
Application.Run( new Form1() );
}
#endregion
private void Form1_Load( object sender, System.EventArgs e )
{
Imaging.Moire_Fringe( (Bitmap)pictureBox2.Image );
}
}
}
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace CSharp_Imaging_Moire_Fringe
{
public class Form1 : System.Windows.Forms.Form
{
#region Windows 窗体设计器生成的代码
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.ComponentModel.IContainer components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(44, 38);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(256, 256);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(332, 38);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(256, 256);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(632, 333);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "C# - Imaging - Moire Fringe";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
[STAThread]
private static void Main()
{
Application.Run( new Form1() );
}
#endregion
private void Form1_Load( object sender, System.EventArgs e )
{
Imaging.Moire_Fringe( (Bitmap)pictureBox2.Image );
}
}
}