IRONSOFTWAREHOME
Set Pixel
using IronSoftware.Drawing;

AnyBitmap bitmap = AnyBitmap.FromFile(@"sample.jpg");

// Create horizontal line with magenta color
for (int i = 1157; i < 2382; i++)
{
    bitmap.SetPixel(i, 869, Color.Magenta);
}
bitmap.SaveAs("underlined.jpg");
NuGet Download
PM > Install-Package IronSoftware.System.Drawing
Set Pixel

Set Pixel

The SetPixel() method in the AnyBitmap class is used to apply colors to specific pixels on an image. This is useful for drawing or simply creating a line on an image using a specified color.

The SetPixel() method is found under the AnyBitmap class in IronSoftware.Drawing. It accepts three parameters: the x coordinate, the y coordinate, and an IronSoftware.Drawing.Color object. The method can be called on an AnyBitmap object to apply the color to the AnyBitmap image.

In the provided code snippet, a sample image was loaded using the AnyBitmap.FromFile() method, which returns an AnyBitmap object. A for loop was used to create a colored horizontal line by changing the x coordinate. The bitmap with the applied pixels is then saved to the machine with a different name.

View on GitHub

Ready to Get Started?

Nuget Downloads 19,926,787Version:2025.3just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required