///
/// 剪切白边(上下左右)
///
///
///
public static Bitmap Crop(Bitmap b)
{
int x, y;//for use of X,Y Coordinates of pixels
Color c = new Color(); //pixel color for use of identifying if background
int intLeft = 0;//furthest left X coordinate
int intRight = 0;//furthest right X coordinate
int intBottom = 0;//furthest to the bottom Y coordinate
int intTop = 0;
y = 0;
while (y < b.Height)
{
x = 0;
while (x < b.Width) //loop through pixels on X axis until end of image width
{
c = b.GetPixel(x, y); //Get the color of the pixel
if (c.R != 255 && c.R != 0 && c.G != 255 && c.G != 0 && c.B != 255 && c.B != 0)
{
if (c.R < 240 || c.G < 240 || c.B < 240)
{
//Determine if pixel is further left than the value we already have
.net c# 图片去白边
最新推荐文章于 2024-01-05 14:01:51 发布
这段代码提供了一个C#方法,用于裁剪图片的白边。通过遍历图片的像素,判断非白色像素的位置,确定图片内容的实际边界,然后创建一个新的Bitmap对象,将无白边的内容绘制到新图片上,从而实现去白边效果。
摘要由CSDN通过智能技术生成