开发者

Delete pixel in a bitmap

开发者 https://www.devze.com 2023-03-01 21:03 出处:网络
Is there a way for me to delete a single pixel in a bitmap in C#? I already tried开发者_开发技巧 to look for a solution on the internet but I cant find one. What exactly do you mean with \"delete a pi

Is there a way for me to delete a single pixel in a bitmap in C#? I already tried开发者_开发技巧 to look for a solution on the internet but I cant find one.


What exactly do you mean with "delete a pixel"? Bitmaps are (usually) rectangular grids of pixels with all of them having a defined value.

You can set the color of a single pixel by using SetPixel on a Bitmap object. This can be fully-transparent, too.


I don't think that is possible to "delete" a pixel, but you can set it to a specified color.

// Open your image
string path = "./path/to/your_image.bmp";
Bitmap img = (Bitmap)Bitmap.FromFile(path);

// Supporting variables
int x = 5;
int y = 5;
Color color = Color.Black;

// Actual operation
img.SetPixel(x, y, color);
img.Save(path);
0

精彩评论

暂无评论...
验证码 换一张
取 消