/ * Note: In accordance with the specified size, generate thumbnails of: Blue.Dream Disclaimer: I recently discovered that many website quoted the article, saying that the author information are omitted, please reference the author of this site do not omit author of * / using system.drawing; using system.drawing.imaging; using system.collections; using system.bomponentmodel; using system.data; using system.io;
A summary description of Namespace Test {///
Public Form1 () {// // Windows Form Designer Support for // InitializeComponent (); this.init ();
// // Todo: Add any constructor code after INITIALIZEComponent call //}
private void Init () {DataTable ht = new DataTable (); DataColumn objcol = new DataColumn ( "Keys"); objcol.DataType = typeof (System.String); ht.Columns.Add (objcol); objcol = new DataColumn ( "Value"); objcol.datatype = typeof (system.int32); ht.columns.add (objcol); DATAROW ROW = HT.NEWROW (); Row [0] = "800 * 600"; Row [1] = 1; ht.rows.add (rot); row = ht.newrow (); row [0] = "640 * 480"; row [1] = 2; ht.rows.add (row); row = HT. NEWROW (); row [0] = "420 * 360"; row [1] = 3; ht.rows.add (row); row = ht.newrow (); row [0] = "340 * 270"; Row [1] = 4; ht.rows.add (row); row = ht.newrow (); row [0] = "240 * 180"; row [1] = 5; ht.rows.add (row) Row = ht.newrow (); row [0] = "120 * 90"; row [1] = 6; ht.rows.add (row); this.local.dataSource = ht; this.local.displaymember = "Keys"; this.local.valuemember = "value";} ///
#Region Windows Form Designer Generated Code ///
/// summary> private void InitializeComponent () {this.groupBox1 = new System.Windows.Forms.GroupBox (); this.imgSource = new System.Windows.Forms.PictureBox (); this.groupBox2 = new System. Windows.Forms.GroupBox (); this.imgObject = new System.Windows.Forms.PictureBox (); this.btn_Browser = new System.Windows.Forms.Button (); this.button2 = new System.Windows.Forms.Button (); This.local = new system.windows.forms.comboBox (); this.label1 = new system.windows.forms.label (); this.groupbox1.suspendlayout (); this.groupbox2.suspendlayout (); this .Suspendlayout (); // // Groupbox1 // this.groupbox1.controls.addrange (new system.windows.forms.control [] {this.imgsource}; this.groupBox1.name = "groupbox1"; this.groupBox1 .Size = new system.drawing.size (288, 296); this.groupbox1.tabindex = 0; this.groupbox1.tabstop = false; this.groupBox1.text = "source map"; /// ivsource // this .imgsource.location = new system.drawing.point (8, 16); this.imgsource.name = "imgsource"; this.imgsource.size = new system.drawing.size (272, 272); this.imgsource.tabindex = 0; this.imgsource.tabstop = false; /// Groupbox2 / / This.groupbox2.controls.addrange (new system.windows.forms.control [] {this.imgobject}); this.groupbox2.location = new system.drawing.point (304, 0); this.groupbox2.name = "GROUPBOX2"; this.groupbox2.size = new system.drawing.size (352, 296); this.groupbox2.tabindex = 0; this.groupbox2.tabstop = false; this.groupBox2.text = "result map";
// // imgobject // this.imgObject.location = new system.drawing.point (8, 16); this.imgobject.name = "imgobject"; this.imgobject.size = new system.drawing.size (336, 272); this.imgobject.tabindex = 0; this.imgobject.tabstop = false; // // btn_browser // this.btn_browser.location = new system.drawing.point (24, 312); this.btn_browser.name = "btn_Browser"; this.btn_Browser.TabIndex = 1; this.btn_Browser.Text = "source image"; this.btn_Browser.Click = new System.EventHandler (this.btn_Browser_Click); // // button2 // this.button2 .Location = new system.drawing.point (552, 312); this.button2.name = "button2"; this.button2.tabindex = 2; this.button2.text = "generated"; this.button2.click = New system.eventhandler (this.button2_click); // // local // this.local.location = new system.drawing.point (256, 312); this.local.name = "local"; this.local.size = New System.drawing.size (112, 20); this.local.tabindex = 4; this.local.text = "- Please select -"; // // label1 // this.label1.location = new system.drawing.point (216, 312); this.label1.name = "label1"; this.label1.size = new system.drawing.size (32, 23) ; this.label1.TabIndex = 6; this.label1.Text = "size"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size (6, 14); this.ClientSize = new system.drawing.size (664, 365);
This.controls.addrange (new system.windows.forms.control [] {this.Label1, this.local, this.button2, this.btn_browser, this.group, this.groupbox2}; this.name = "Form1" This.Text = "Form1"; this.groupBox1.ResumeLayout (false); this.groupBox2.ResumeLayout (false); this.ResumeLayout (false);} #ENDREGION
///
Private void button2_click (object sender, system.eventargs e) {intate = (int) this.local.selectedValue; point p = new point (340, 270); switch (select) {case 1: px = 800; py = 600; Break; case 2: px = 640; py = 480; Break; case 3: px = 480; py = 360; Break; case 4: py = 340; px = 270; break; case 5: px = 240; py = 180; Break; Case 6: PX = 120; py = 90; Break;}
// object address generating FileInfo objFile = new FileInfo (this.SourceFile); string filepath = objFile.DirectoryName; string filename = objFile.Name; string saveFile = filepath "// Thumb" filename; if (MakeThumbnailImage (this. Sourcefile, Savefile, PX, Py, Objfile.extension.tolower ()) This.Imgobject.Image = New Bitmap (Savefile); Else MessageBox.show ("Fails");}
///
private System.Drawing.Imaging.ImageFormat GetImageType (string strType) {switch (strType) {case ".jpg": return ImageFormat.Jpeg; case ".jpeg": return ImageFormat.Jpeg; case ".gif": return ImageFormat. GIF; case ".bmp": return imageformat.bmp; case ".tiff": return imageformat.tiff; case ".ico": return imageformat.icon; case ".png": return imageformat.png; casser ".emf ": Return imageformat.emf; default: return imageformat.jpeg;}} private bool thumbnailcallback () {returnaf false;}}}