当前位置: 首页>>代码示例>>C#>>正文


C# Surface.Lock方法代码示例

本文整理汇总了C#中Surface.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# Surface.Lock方法的具体用法?C# Surface.Lock怎么用?C# Surface.Lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Surface的用法示例。


在下文中一共展示了Surface.Lock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BlitRGB32

		/// <summary>
		/// Blits the RGB-Bitmap to a RGB32 Surface
		/// </summary>
		/// <param name="src">RGB Bitmap</param>
		/// <param name="dest">RGB32 Surface</param>
		public unsafe void BlitRGB32( Bitmap src, Surface dest ) {
			BitmapData ds = src.LockBits( new Rectangle( 0, 0, src.Width, src.Height ), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb );
			try {
				LockedData dd = dest.Lock( LockFlags.WriteOnly );

				try {
					int ps = ds.Stride - ( ds.Width * 3 );
					byte[] pd = new byte[ dd.Pitch - ( dd.Width * 4 ) ];

					byte* ptr = (byte*)ds.Scan0;

					for( int h = 0; h < ds.Height; h++ ) {
						for( int w = 0; w < ds.Width; w += 1 ) {
							byte[] dbuf = new byte[ 4 ]; //2 pixel (2x16)

							byte r = ptr[ 0 ];
							byte g = ptr[ 1 ];
							byte b = ptr[ 2 ];

							ptr += 3;

							dbuf[ 0 ] = r;
							dbuf[ 1 ] = g;
							dbuf[ 2 ] = b;

							dd.Data.Write( dbuf, 0, dbuf.Length );
						}

						ptr += ps;

						if( pd.Length > 0 )
							dd.Data.Write( pd, 0, pd.Length );

					}
				} finally {
					dest.Unlock();
				}
			} finally {
				src.UnlockBits( ds );
			}
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:46,代码来源:OverlayLib.cs

示例2: BlitYUY2

		/// <summary>
		/// Blits the RGB Bitmap to a YUY2 surface
		/// </summary>
		/// <param name="src">RGB Bitmap</param>
		/// <param name="dest">YUY2 Surface</param>
		public unsafe void BlitYUY2( Bitmap src, Surface dest ) {
			BitmapData ds = src.LockBits( new Rectangle( 0, 0, src.Width, src.Height ), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb );
			try {
				LockedData dd = dest.Lock( LockFlags.WriteOnly );

				try {
					int ps = ds.Stride - ( ds.Width * 3 );
					byte[] pd = new byte[ dd.Pitch - ( dd.Width * 2 ) ];

					byte* ptr = (byte*)ds.Scan0;

					for( int h = 0; h < ds.Height; h++ ) {
						for( int w = 0; w < ds.Width; w += 2 ) {
							byte[] dbuf = new byte[ 4 ]; //2 pixel (2x16bit)

							byte r1 = ptr[ 0 ];
							byte g1 = ptr[ 1 ];
							byte b1 = ptr[ 2 ];

							ptr += 3;

							byte r2 = ptr[ 0 ];
							byte g2 = ptr[ 1 ];
							byte b2 = ptr[ 2 ];

							ptr += 3;

							//Dont ask me for the conversion formulas - They are from FourCC and a bit of own modifications to match colors better
							dbuf[ 0 ] = (byte)Math.Min( 255, ( 0.230 * r1 ) + ( 0.600 * g1 ) + ( 0.170 * b1 ) ); //Yo - luminescent 1
							dbuf[ 2 ] = (byte)Math.Min( 255, ( 0.230 * r2 ) + ( 0.600 * g2 ) + ( 0.170 * b2 ) ); //Y1 - luminescent 2
							dbuf[ 1 ] = (byte)Math.Min( 255, +( 0.439 * r1 ) - ( 0.368 * g1 ) - ( 0.071 * b1 ) + 128 ); //Ux - same for both
							dbuf[ 3 ] = (byte)Math.Min( 255, -( 0.148 * r1 ) - ( 0.291 * g1 ) + ( 0.439 * b1 ) + 128 ); //Vx - same for both

							dd.Data.Write( dbuf, 0, dbuf.Length );
						}
						ptr += ps;

						if( pd.Length > 0 ) {
							dd.Data.Write( pd, 0, pd.Length );
						}
					}
				} catch( Exception e ) {
					MessageBox.Show( e.ToString() );
				} finally {
					dest.Unlock();
				}
			} catch( Exception e ) {
				System.Diagnostics.Debug.WriteLine( e );
			} finally {
				src.UnlockBits( ds );
			}
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:57,代码来源:OverlayLib.cs


注:本文中的Surface.Lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。