Eto.Drawing.Bitmap.Lock C# (CSharp) Méthode

Lock() public méthode

Locks the data of the image to directly access the bytes of the image
This locks the data to read and write to directly using unsafe pointers. After reading or updating the data, you must call BitmapData.Dispose() to unlock the data before using the bitmap. e.g.: using (var bd = bitmap.Lock ()) { byte* pdata = bd.Data; // access data }
public Lock ( ) : Eto.Drawing.BitmapData
Résultat Eto.Drawing.BitmapData
		public BitmapData Lock()
		{
			return Handler.Lock();
		}

Usage Example

Exemple #1
0
		void DrawTest(Bitmap image)
		{
			// should always ensure .Dispose() is called when you are done with a Graphics or BitmapData object.

			// Test setting pixels directly
			using (var bd = image.Lock())
			{
				var sz = image.Size / 5;
				for (int x = sz.Width; x < sz.Width * 2; x++)
					for (int y = sz.Height; y < sz.Height * 2; y++)
						bd.SetPixel(x, y, Colors.Green);
			}

			// Test using Graphics object
			using (var graphics = new Graphics(image))
			{
				graphics.DrawLine(Pens.Blue, Point.Empty, new Point(image.Size));
				graphics.DrawRectangle(Pens.Blue, new Rectangle(image.Size - 1));
			}

			// should be able to set pixels after using graphics object
			using (var bd = image.Lock())
			{
				var sz = image.Size / 5;
				for (int x = sz.Width * 3; x < sz.Width * 4; x++)
					for (int y = sz.Height * 3; y < sz.Height * 4; y++)
						bd.SetPixel(x, y, Colors.Red);
			}

		}
All Usage Examples Of Eto.Drawing.Bitmap::Lock