SetPixel()
method to overwrite parts of the bitmap.PictureBox
using GDI+ and then, to make it permanent, perform the same drawing on the Image
object being displayed. You would need some way to store the data representing the drawing to do it that way. If you want to make it permanent immediately, you can just draw onto the Image in the first place. If you want to do that, you should do some reading on GDI+ first. You should understand the subject first, rather than just trying to copy and paste code that others have written for you, which you'd have no idea how to debug or modify.,One way is to access the bitmap object and use theSetPixel()
method to overwrite parts of the bitmap.
using System;
using System.Drawing;
class Program
{
static void Main()
{
// Load the BMP image
Bitmap bmp = new Bitmap("path_to_your_image.bmp");
// Alter a specific area (e.g., a rectangle)
for (int x = 50; x < 100; x++)
{
for (int y = 50; y < 100; y++)
{
// Change the pixel color to white
bmp.SetPixel(x, y, Color.White);
}
}
// Save the modified image
bmp.Save("modified_image.bmp");
}
}
using System;
using System.Drawing;
class Program
{
static void Main()
{
Bitmap bitmap = new Bitmap("path_to_your_image.jpg");
// Define the area to delete (x, y, width, height)
Rectangle deleteArea = new Rectangle(50, 50, 100, 100);
// Set the pixels in the defined area to transparent
for (int x = deleteArea.X; x < deleteArea.X + deleteArea.Width; x++)
{
for (int y = deleteArea.Y; y < deleteArea.Y + deleteArea.Height; y++)
{
bitmap.SetPixel(x, y, Color.Transparent);
}
}
// Save the modified image
bitmap.Save("modified_image.png");
}
}