Edit a BMP image in PictureBox.

One way is to access the bitmap object and use the SetPixel() method to overwrite parts of the bitmap.
 
It depends exactly what you want to do. One option is to allow the user to draw on the 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.,
 
*** removed unnecessary quote ***

I do not expect to receive any code to copy/paste.
I began programming in DOS in 1982! Then Basic! Then C! Then C#! I merely wanted a nudge to where I could find an alternative method which I could use in VS 2022. Anyway .... I worked it out. Because I also have vast experience in GDI. But I have a better solution.
 
Last edited by a moderator:
For future reference, I recommend providing more detail in your question. Then we won't have to make guesses or assumptions about what you have and what you know and you won't have to explain why those guesses or assumptions aren't correct. Assume that too many words is better than not enough.
 
The question seeks to understand how to edit a BMP image, specifically whether it is possible to delete or alter parts of the image?
Editing a BMP image can be accomplished using the System.Drawing namespace, which provides a range of classes for working with images. You can load a BMP image, manipulate its pixels, and save the changes. To delete or alter a part of the image, you can use the Bitmap class to access and modify individual pixels.

Editing BMP Images in C#:
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");
    }
}

Deleting Parts of an image:
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");
    }
}
 
How is your post #7 different from what was said in post #2 other than the spoon-feeding of code... Code which the OP obviously didn't need because he says he has a lot of GDI experience, and he has already solved the issue?
 
Back
Top Bottom