Exemple #1
0
		/// <summary>
		/// 获得设备上下文中指定区域的位图对象
		/// </summary>
		/// <param name="Left">区域左边位置</param>
		/// <param name="Top">区域顶端位置</param>
		/// <param name="Width">宽度</param>
		/// <param name="Height">高度</param>
		/// <returns>获得的BMP位图对象</returns>
		public System.Drawing.Bitmap GetBMP( int Left , int Top , int Width , int Height )
		{
			DeviceCapsClass cap = new DeviceCapsClass( this.intHDC );
			if( Left < 0 ) Left = 0 ;
			if( Top < 0 ) Top = 0 ;
			if( Left + Width > cap.HORZRES )
				Width = cap.HORZRES - Left ;
			if( Top + Height > cap.VERTRES )
				Height = cap.VERTRES - Top ;
			if( Width <= 0 || Height <= 0 )
				return null;
			IntPtr memdc = NativeCreateCompatibleDC( this.intHDC );
			if( memdc.ToInt32() == 0)
				return null;
			IntPtr bmp = CreateCompatibleBitmap( this.intHDC , Width , Height );
			if( bmp.ToInt32() == 0 )
				return null;
			IntPtr oldbmp = SelectObject( memdc , bmp );
			BitBlt( memdc , 0 , 0 , Width , Height , this.intHDC , Left , Top , 0xcc0020 );
			bmp = SelectObject( memdc , oldbmp);
			DeleteDC( memdc );
			System.Drawing.Bitmap myBmp = System.Drawing.Bitmap.FromHbitmap(bmp );
			return myBmp ;
		}
Exemple #2
0
		/// <summary>
		/// 获得设备上下文中所有区域的位图对象
		/// </summary>
		/// <returns>BMP位图对象</returns>
		public System.Drawing.Bitmap GetBMP( )
		{
			DeviceCapsClass cap = new DeviceCapsClass( this.intHDC );
			return GetBMP( 0 , 0 , cap.HORZRES , cap.VERTRES );
		}