www.pudn.com > WebGisMapx.rar > MapServer.cs


using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.IO; 
 
namespace WebGis 
{ 
 
	public class MapServer : System.Windows.Forms.Form 
	{ 
		private AxMapXLib.AxMap axMap1; 
		private System.Windows.Forms.Button button1; 
		private System.Windows.Forms.PictureBox pictureBox1; 
 
		private System.ComponentModel.Container components = null; 
 
		public MapServer() 
		{ 
			InitializeComponent(); 
		} 
 
		 
		protected override void Dispose( bool disposing ) 
		{ 
			if( disposing ) 
			{ 
				if (components != null)  
				{ 
					components.Dispose(); 
				} 
			} 
			base.Dispose( disposing ); 
		} 
 
 
		private void InitializeComponent() 
		{ 
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MapServer)); 
			this.axMap1 = new AxMapXLib.AxMap(); 
			this.button1 = new System.Windows.Forms.Button(); 
			this.pictureBox1 = new System.Windows.Forms.PictureBox(); 
			((System.ComponentModel.ISupportInitialize)(this.axMap1)).BeginInit(); 
			this.SuspendLayout(); 
			//  
			// axMap1 
			//  
			this.axMap1.Enabled = true; 
			this.axMap1.Location = new System.Drawing.Point(16, 16); 
			this.axMap1.Name = "axMap1"; 
			this.axMap1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap1.OcxState"))); 
			this.axMap1.Size = new System.Drawing.Size(360, 344); 
			this.axMap1.TabIndex = 0; 
			//  
			// button1 
			//  
			this.button1.Location = new System.Drawing.Point(560, 424); 
			this.button1.Name = "button1"; 
			this.button1.TabIndex = 1; 
			this.button1.Text = "button1"; 
			this.button1.Click += new System.EventHandler(this.button1_Click); 
			//  
			// pictureBox1 
			//  
			this.pictureBox1.Location = new System.Drawing.Point(400, 16); 
			this.pictureBox1.Name = "pictureBox1"; 
			this.pictureBox1.Size = new System.Drawing.Size(328, 312); 
			this.pictureBox1.TabIndex = 2; 
			this.pictureBox1.TabStop = false; 
			//  
			// MapServer 
			//  
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); 
			this.ClientSize = new System.Drawing.Size(768, 493); 
			this.Controls.Add(this.pictureBox1); 
			this.Controls.Add(this.button1); 
			this.Controls.Add(this.axMap1); 
			this.Name = "MapServer"; 
			this.Text = "Form1"; 
			((System.ComponentModel.ISupportInitialize)(this.axMap1)).EndInit(); 
			this.ResumeLayout(false); 
 
		} 
 
 
		private void button1_Click(object sender, System.EventArgs e) 
		{ 
			byte[] buffer = buildMap("testmap"); 
			MemoryStream stream = new MemoryStream(buffer); 
			Image img = Bitmap.FromStream(stream); 
			pictureBox1.Image = img; 
		} 
 
		public byte[] buildMap(string filename) 
		{ 
			Bitmap bmp = new Bitmap(axMap1.Width, axMap1.Height); 
			Graphics g = Graphics.FromImage(bmp); 
			IntPtr hDC = g.GetHdc(); 
			axMap1.PrintMap((int)hDC, 0, 0, bmp.Width * 20, bmp.Height * 20); 
			g.ReleaseHdc(hDC); 
			MemoryStream stream = new MemoryStream(); 
			bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); 
			return stream.GetBuffer(); 
		} 
	} 
}