.net c# 图片去白边

这段代码提供了一个C#方法,用于裁剪图片的白边。通过遍历图片的像素,判断非白色像素的位置,确定图片内容的实际边界,然后创建一个新的Bitmap对象,将无白边的内容绘制到新图片上,从而实现去白边效果。
摘要由CSDN通过智能技术生成

///
/// 剪切白边(上下左右)
///
///
///
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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值