edit a picture in csharp

To edit a picture in C#, you can use the Bitmap and Graphics classes from the System.Drawing namespace.

Here's an example of how to invert the colors of an image:

main.cs
// Load the image
Bitmap originalImage = new Bitmap("image.jpg");

// Create a new bitmap and graphics object
Bitmap editedImage = new Bitmap(originalImage.Width, originalImage.Height);
Graphics graphics = Graphics.FromImage(editedImage);

// Invert the colors of the image
ColorMatrix colorMatrix = new ColorMatrix(new float[][] {
    new float[] {-1, 0, 0, 0, 0},
    new float[] {0, -1, 0, 0, 0},
    new float[] {0, 0, -1, 0, 0},
    new float[] {0, 0, 0, 1, 0},
    new float[] {1, 1, 1, 0, 1}
});
ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(colorMatrix);
graphics.DrawImage(originalImage, new Rectangle(0, 0, originalImage.Width, originalImage.Height),
    0, 0, originalImage.Width, originalImage.Height, GraphicsUnit.Pixel,
    imageAttributes);

// Save the edited image
editedImage.Save("edited_image.jpg", ImageFormat.Jpeg);
880 chars
24 lines

In this example, we first load the original image. Then, we create a new Bitmap and Graphics object to hold the edited image. We use a ColorMatrix to invert the colors of the original image and apply it to the edited image using the DrawImage method. Finally, we save the edited image to a new file.

This is just one example of the many image editing operations you can perform using C# and the System.Drawing namespace.

gistlibby LogSnag