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


C# Bitmap.LockBitsUnlock方法代码示例

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


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

示例1: GetIndexedDataLinearTest

		public unsafe void GetIndexedDataLinearTest()
		{
			Bitmap Bitmap = new Bitmap(3, 3, PixelFormat.Format8bppIndexed);

			Bitmap.LockBitsUnlock(PixelFormat.Format8bppIndexed, (BitmapData) =>
			{
				byte *Data = (byte *)BitmapData.Scan0.ToPointer();
				for (int n = 0; n < 9; n++) Data[n] = (byte)n;
			});

			Assert.AreEqual(
				"000102030405060708",
				Bitmap.GetIndexedDataLinear().ToHexString()
			);
		}
开发者ID:sweetwxh,项目名称:csharputils,代码行数:15,代码来源:BitmapExtensionTest.cs

示例2: GetMask

		/// <summary>
		/// 
		/// </summary>
		/// <param name="Bitmap"></param>
		/// <param name="AlphaThresold"></param>
		/// <returns></returns>
		static public bool[,] GetMask(Bitmap Bitmap, byte AlphaThresold = 1)
		{
			var Width = Bitmap.Width;
			var Height = Bitmap.Height;
			var Mask = new bool[Bitmap.Width, Bitmap.Height];
			Bitmap.LockBitsUnlock(System.Drawing.Imaging.PixelFormat.Format32bppArgb, (BitmapData) => {
				for (int y = 0; y < Height; y++)
				{
					var Ptr = ((byte *)BitmapData.Scan0.ToPointer()) + BitmapData.Stride * y;
					Ptr += 3;
					for (int x = 0; x < Width; x++)
					{
						Mask[x, y] = (*Ptr >= AlphaThresold);
						Ptr += 4;
						//Console.Write(Mask[x, y] ? 1 : 0);
					}
					//Console.WriteLine("");
				}
			});
			return Mask;
		}
开发者ID:soywiz,项目名称:csharputils,代码行数:27,代码来源:DistanceMap.cs

示例3: ToBitmap

        public Bitmap ToBitmap()
        {
            var Bitmap = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
            Bitmap.LockBitsUnlock(PixelFormat.Format32bppArgb, (BitmapData) =>
            {
                int Count = Width * Height;
                var Output = (OutputPixel*)BitmapData.Scan0;
                PixelFormatDecoder.Decode(
                    GuPixelFormat,
                    Address,
                    Output,
                    Width,
                    Height,
                    IgnoreAlpha: true
                );

                for (int n = 0; n < Count; n++)
                {
                    var Color = Output[n];
                    Output[n].R = Color.B;
                    Output[n].G = Color.G;
                    Output[n].B = Color.R;
                    Output[n].A = 0xFF;
                }
            });
            return Bitmap;
        }
开发者ID:soywiz,项目名称:cspspemu,代码行数:27,代码来源:PspBitmap.cs

示例4: TransferChannelsDataLinear

        public static unsafe void TransferChannelsDataLinear(Rectangle Rectangle, Bitmap Bitmap, byte[] NewData, Direction Direction, params BitmapChannel[] Channels)
        {
            int WidthHeight = Bitmap.Width * Bitmap.Height;
            var FullRectangle = Bitmap.GetFullRectangle();
            if (!FullRectangle.Contains(Rectangle.Location)) throw(new InvalidProgramException());
            if (!FullRectangle.Contains(Rectangle.Location + Rectangle.Size - new Size(1, 1))) throw (new InvalidProgramException());

            int NumberOfChannels = 1;
            foreach (var Channel in Channels)
            {
                if (Channel != BitmapChannel.Indexed)
                {
                    NumberOfChannels = 4;
                    break;
                }
            }

            Bitmap.LockBitsUnlock((NumberOfChannels == 1) ? PixelFormat.Format8bppIndexed : PixelFormat.Format32bppArgb, (BitmapData) =>
            {
                byte* BitmapDataScan0 = (byte*)BitmapData.Scan0.ToPointer();
                int Width = Bitmap.Width;
                int Height = Bitmap.Height;
                int Stride = BitmapData.Stride;
                if (NumberOfChannels == 1)
                {
                    Stride = Width;
                }

                int RectangleTop = Rectangle.Top;
                int RectangleBottom = Rectangle.Bottom;
                int RectangleLeft = Rectangle.Left;
                int RectangleRight = Rectangle.Right;

                fixed (byte* OutputPtrStart = &NewData[0])
                {
                    byte* OutputPtr = OutputPtrStart;
                    foreach (var Channel in Channels)
                    {
                        for (int y = RectangleTop; y < RectangleBottom; y++)
                        {
                            byte* InputPtr = BitmapDataScan0 + Stride * y;
                            if (NumberOfChannels != 1)
                            {
                                InputPtr = InputPtr + (int)Channel;
                            }
                            InputPtr += NumberOfChannels * RectangleLeft;
                            for (int x = RectangleLeft; x < RectangleRight; x++)
                            {
                                if (Direction == Direction.FromBitmapToData)
                                {
                                    *OutputPtr = *InputPtr;
                                }
                                else
                                {
                                    *InputPtr  = * OutputPtr;
                                }
                                OutputPtr++;
                                InputPtr += NumberOfChannels;
                            }
                        }
                    }
                }
            });
        }
开发者ID:yash0924,项目名称:csharputils,代码行数:64,代码来源:BitmapUtils.cs

示例5: TransferChannelsDataInterleaved

		public static unsafe void TransferChannelsDataInterleaved(Rectangle Rectangle, Bitmap Bitmap, byte* NewDataPtr, Direction Direction, params BitmapChannel[] Channels)
		{
			int NumberOfChannels = 1;
			foreach (var Channel in Channels)
			{
				if (Channel != BitmapChannel.Indexed)
				{
					NumberOfChannels = 4;
					break;
				}
			}

			Bitmap.LockBitsUnlock(Rectangle, (NumberOfChannels == 1) ? PixelFormat.Format8bppIndexed : PixelFormat.Format32bppArgb, (BitmapData) =>
			{
				for (int y = 0; y < BitmapData.Height; y++)
				{
					byte* BitmapPtr = ((byte*)BitmapData.Scan0.ToPointer()) + BitmapData.Stride * y;
					byte* DataPtr = NewDataPtr + (NumberOfChannels * BitmapData.Width) * y;
					int z = 0;
					for (int x = 0; x < BitmapData.Width; x++)
					{
						for (int c = 0; c < NumberOfChannels; c++)
						{
							byte* DataPtrPtr = &DataPtr[z + c];
							byte* BitmapPtrPtr = &BitmapPtr[z + (int)Channels[c]];

							if (Direction == BitmapUtils.Direction.FromBitmapToData)
							{
								*DataPtrPtr = *BitmapPtrPtr;
							}
							else
							{
								*BitmapPtrPtr  = * DataPtrPtr;
							}
						}
						z += NumberOfChannels;
					}
				}
			});
		}
开发者ID:sweetwxh,项目名称:csharputils,代码行数:40,代码来源:BitmapUtils.cs

示例6: BitmapFromDistanceMap

		/// <summary>
		/// 
		/// </summary>
		/// <param name="DistanceMap"></param>
		/// <returns></returns>
		static public Bitmap BitmapFromDistanceMap(DistanceEntry[,] DistanceMap)
		{
			var Bitmap = new Bitmap(DistanceMap.GetLength(0), DistanceMap.GetLength(1));
			var Width = Bitmap.Width;
			var Height = Bitmap.Height;
			Bitmap.LockBitsUnlock(System.Drawing.Imaging.PixelFormat.Format32bppArgb, (BitmapData) =>
			{
				for (int y = 0; y < Height; y++)
				{
					var Ptr = ((byte *)BitmapData.Scan0.ToPointer()) + BitmapData.Stride * y;
					for (int x = 0; x < Width; x++)
					{
						byte Distance = (byte)MathUtils.FastClamp((int)(DistanceMap[x, y].Distance * 4), 0, 255);
						*Ptr++ = Distance;
						*Ptr++ = Distance;
						*Ptr++ = Distance;
						*Ptr++ = 0xFF;
					}
				}
			});
			return Bitmap;
		}
开发者ID:soywiz,项目名称:csharputils,代码行数:27,代码来源:DistanceMap.cs

示例7: Load

 public Texture Load(string FileName)
 {
     var Bitmap = new Bitmap(Image.FromFile(FileName));
     Bitmap.LockBitsUnlock(System.Drawing.Imaging.PixelFormat.Format32bppArgb, (BitmapData) =>
     {
         this.SetData((OutputPixel *)BitmapData.Scan0, BitmapData.Width, BitmapData.Height);
     });
     return this;
 }
开发者ID:SsJVasto,项目名称:cspspemu,代码行数:9,代码来源:TextureCache.cs


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