خواندن و نوشتن رنگ یک پیکسل
کد:
using System.Drawing.Imaging;
کد:
Bitmap bmp = new Bitmap(picturebox1.Image);
//read
Color c = bmp.GetPixel(1, 1);
//write
bmp.SetPixel(2, 2, c);
مثال -
کد:
<font color="blue">private</font> <font color="blue">void</font> GetPixel_Example
(PaintEventArgs e)
{
<font color="green">// Create a Bitmap object from an image file.</font>
Bitmap myBitmap = <font color="blue">new</font> Bitmap(<font color="maroon">
<font color="maroon">"Grapes.jpg"</font></font>);
<font color="green">// Get the color of a pixel within myBitmap.</font>
Color pixelColor = myBitmap.GetPixel(50, 50);
<font color="green">// Fill a rectangle with pixelColor.</font>
SolidBrush pixelBrush = <font color="blue">new</font> SolidBrush(pixelColor);
e.Graphics.FillRectangle(pixelBrush, 0, 0, 100, 100);
}