⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usercontrol1.cs

📁 mpeg4压缩算法程序
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.IO;
using BitmapImage;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;


namespace MPEGBuilder1UI
{
	/// <summary>
	/// Summary description for UserControl1.
	/// </summary>
	public class UserControl1 : System.Windows.Forms.UserControl
	{
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.PictureBox pictureBox2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.ComponentModel.IContainer components;

		public int mode = 16;
		public int nPictures = 1;
		private double stretchX = 1.0;
		private double stretchY = 1.0;
		private int xPos = 0;
		private int yPos = 0;
		private long outBytes = 0;
		private long inputFileLength = 0;

		public System.Windows.Forms.TextBox textBox1;
		public System.Windows.Forms.TextBox textBox2;
		public System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.Windows.Forms.ToolTip toolTip2;
		private System.Windows.Forms.ToolTip toolTip3;
		private System.Windows.Forms.Label label2;

		public UserControl1()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			this.SetStyle(ControlStyles.ResizeRedraw, true);
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.DoubleBuffer, true);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component 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.components = new System.ComponentModel.Container();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.pictureBox2 = new System.Windows.Forms.PictureBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
			this.toolTip2 = new System.Windows.Forms.ToolTip(this.components);
			this.toolTip3 = new System.Windows.Forms.ToolTip(this.components);
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
			this.pictureBox1.Location = new System.Drawing.Point(16, 32);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(352, 352);
			this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			this.toolTip1.SetToolTip(this.pictureBox1, "Use File->Open To Load Image");
			this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
			this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
			// 
			// pictureBox2
			// 
			this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.pictureBox2.Cursor = System.Windows.Forms.Cursors.Cross;
			this.pictureBox2.Location = new System.Drawing.Point(424, 32);
			this.pictureBox2.Name = "pictureBox2";
			this.pictureBox2.Size = new System.Drawing.Size(128, 128);
			this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox2.TabIndex = 1;
			this.pictureBox2.TabStop = false;
			this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click);
			this.pictureBox2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseMove);
			this.pictureBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseDown);
			// 
			// button1
			// 
			this.button1.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.button1.Location = new System.Drawing.Point(448, 192);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(75, 32);
			this.button1.TabIndex = 1;
			this.button1.Text = "Block Details";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(448, 344);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(75, 32);
			this.button2.TabIndex = 0;
			this.button2.Text = "Exit";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// textBox1
			// 
			this.textBox1.BackColor = System.Drawing.SystemColors.ScrollBar;
			this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox1.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.textBox1.Location = new System.Drawing.Point(64, 392);
			this.textBox1.Name = "textBox1";
			this.textBox1.ReadOnly = true;
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "XBlock:";
			// 
			// textBox2
			// 
			this.textBox2.BackColor = System.Drawing.SystemColors.ScrollBar;
			this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox2.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.textBox2.Location = new System.Drawing.Point(176, 392);
			this.textBox2.Name = "textBox2";
			this.textBox2.ReadOnly = true;
			this.textBox2.TabIndex = 3;
			this.textBox2.Text = "YBlock:";
			// 
			// textBox3
			// 
			this.textBox3.BackColor = System.Drawing.SystemColors.ScrollBar;
			this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox3.Cursor = System.Windows.Forms.Cursors.Arrow;
			this.textBox3.Location = new System.Drawing.Point(424, 168);
			this.textBox3.Name = "textBox3";
			this.textBox3.ReadOnly = true;
			this.textBox3.Size = new System.Drawing.Size(144, 13);
			this.textBox3.TabIndex = 4;
			this.textBox3.Text = "Pixel (R,G,B): ";
			this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(100, 16);
			this.label1.TabIndex = 5;
			this.label1.Text = "Loaded Image";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(424, 8);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(144, 16);
			this.label2.TabIndex = 6;
			this.label2.Text = "Zoom In";
			// 
			// UserControl1
			// 
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label2,
																		  this.label1,
																		  this.textBox3,
																		  this.textBox2,
																		  this.textBox1,
																		  this.button2,
																		  this.button1,
																		  this.pictureBox2,
																		  this.pictureBox1});
			this.Name = "UserControl1";
			this.Size = new System.Drawing.Size(576, 432);
			this.Load += new System.EventHandler(this.UserControl1_Load);
			this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.UserControl1_MouseMove);
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			// Block details button
			PixelDisplayDialog dlg = new PixelDisplayDialog((Bitmap) pictureBox2.Image, mode);
			dlg.ShowDialog();	
		}

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

		private void UserControl1_Load(object sender, System.EventArgs e)
		{
			// On load, put a plain black bitmap in PictureBox2
			Bitmap img = new Bitmap(mode,mode);
			int i, j;
			for (i=0; i<mode; i++)
				for (j=0; j<mode; j++)
                    img.SetPixel(i,j,Color.Black);
			pictureBox2.Image = img;

			// On load, put a light gray bitmap in PictureBox2
			Bitmap img1 = new Bitmap(352,352);
			for (i=0; i<352; i++)
				for (j=0; j<352; j++)
					img1.SetPixel(i,j,Color.LightGray);
			pictureBox1.Image = img1;
		}

		public void LoadPictureBox1(string fileName)
		{
			Bitmap img = new Bitmap(fileName);
			ImageFunctions imgF = new ImageFunctions();
			imgF.setImage(img);

			toolTip1.SetToolTip(pictureBox1, "Click on a block to zoom in");
			toolTip2.SetToolTip(pictureBox2, "Display RGB values for pixel at cursor postion");
			toolTip3.SetToolTip(button1, "Display details of Zoom In image");

			FileInfo info = new FileInfo(fileName);
			inputFileLength = info.Length;

			//	In this section the loaded image is resized so that the height
			//	and width are multiples of 16.  That needs to be done because
			//	MPEG macroblocks are 16x16 pixels.
			Size imgSize = imgF.getBMPSize();
			int xFill = 0;
			int yFill = 0;
			int xRem, yRem;

			xRem = imgSize.Width%16;
			yRem = imgSize.Height%16;

			if (xRem != 0)
				xFill = 16-xRem;

			if (yRem != 0)
				yFill = 16-yRem;

			//	This is fills in the bitmap to an MPEG regulation size
			Bitmap img1 = new Bitmap(imgSize.Width+xFill, imgSize.Height+yFill);

			if ((xFill != 0) && (yFill == 0))
				imgF.padWidth(img1);
			else if ((xFill == 0) && (yFill != 0))
				imgF.padHeight(img1);
			else if ((xFill != 0) && (yFill != 0))
			{
				Bitmap img2 = new Bitmap(imgSize.Width+xFill, imgSize.Height);
				imgF.padWidth(img2);
				imgF.setImage(img2);
				imgF.padHeight(img1);
			}
			else
				img1 = img;

			//	Load the image into the picture box and if it's smaller than
			//	352x352 leave it alone.  If it is bigger than 352x352
			//	shrink it to fit the box.
			if (img1.Width <= 352 && img1.Height <= 352)
			{
				pictureBox1.Width = img1.Width;
				pictureBox1.Height = img1.Height;
				stretchX = stretchY = 1.0;
				pictureBox1.Image = img1;
			}
			else
			{
				pictureBox1.Width = 352;
				pictureBox1.Height = 352;
				pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
				stretchX = 352.0/img1.Width;
				stretchY = 352.0/img1.Height;
				pictureBox1.Image = img1;
			}
		}

		private void UserControl1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			this.Cursor = Cursors.Arrow;		
		}

		private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			this.Cursor = Cursors.Hand;

			string s2, s3;

			xPos = ((int)(e.X / stretchX))/mode;
			s2 = "XBlock: " + xPos.ToString();
			textBox1.Text = s2;

			yPos = ((int)(e.Y / stretchY))/mode;
			s3 = "YBlock: " + yPos.ToString();
			textBox2.Text = s3;
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -