1.项目要求上传白底的图片要进行裁剪白边,于是同事谢了个函数感觉很好用。

2.

  #region 剪切白边
/// <summary>
/// 剪切白边
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static Image Crop(Image p)
{
int x, y ;//for use of X,Y Coordinates of pixels
Bitmap b = new Bitmap(p); //image needed to crop
Color c = new Color(); //pixel color for use of identifying if background
int intLeft=;//furthest left X coordinate
int intRight=;//furthest right X coordinate
int intBottom =;//furthest to the bottom Y coordinate
int intTop =;
y = ;
while(y < b.Height)
{
x = ;
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 != &&c.R!= && c.G != &&c.G!= && c.B != &&c.B!=)
{
if (c.R < || c.G < || c.B < )
{
//Determine if pixel is further left than the value we already have
if (intLeft == || intLeft > x )
{
intLeft = x;
}
//Determine if pixel is further to the top than the value we already have
if (intTop == || intTop > y )
{
intTop = y;
}
//Determine if pixel is further right than the value we already have
if (intRight <= b.Width && intRight < x )
{
intRight = x;
}
//Determine if pixel is further to the bottom than the value we already have
if (intBottom <= b.Height && intBottom < y )
{
intBottom = y;
}
}
}
x += ;
}
y += ;
}
int intNewWidth = intRight; //Establish width of new cropped image
int intNewHeight = intBottom; //Establish height of new cropped image
Bitmap imgCropped =new Bitmap(intNewWidth - intLeft + , intNewHeight - intTop + );
Graphics objGraphics = Graphics.FromImage(imgCropped);
//set the background color to white (you can choose what you like
objGraphics.Clear(System.Drawing.Color.Transparent);
int intStartTop = - intTop; /// 40 + 5
int intStartLeft = - intLeft; /// 40 + 5
//Draw the original image to your new cropped sized image
objGraphics.DrawImage(b, intStartLeft, intStartTop);
b.Dispose();
objGraphics.Dispose();
//return the Cropped image to the caller
return imgCropped;
}

.net图片自动裁剪白边函数案例的更多相关文章

  1. 如何安装nginx_lua_module模块,升级nginx,nginx-lua-fastdfs-GraphicsMagick动态生成缩略图,实现图片自动裁剪缩放

    如何安装nginx_lua_module模块,升级nginx,nginx-lua-fastdfs-GraphicsMagick动态生成缩略图,实现图片自动裁剪缩放 参考网站:nginx-lua-fas ...

  2. Tengine + Lua + GraphicsMagick 实现图片自动裁剪/缩放

    http://my.oschina.net/eduosi/blog/169606

  3. 【转载】如何让图片按比例响应式缩放、并自动裁剪的css技巧

    原文: http://blog.csdn.net/oulihong123/article/details/54601030 响应式网站.移动端页面在DIV CSS布局中对于图片列表或图片排版时, 如果 ...

  4. C#开发自动照片(图片)裁剪(缩放)工具

    1.需求分析 用winform窗体程序,开发一个能够自动.批量对图片进行缩放和裁剪的程序. 原本想直接从网上找类型的工具直接用,但是无奈现在网上能找到的工具,要么不能用,要么就是很 恶心的下载完后还有 ...

  5. 一行代码彻底禁用WordPress缩略图自动裁剪功能

    记得在博客分享七牛缩略图教程的时候,提到过 WordPress 默认会将上传的图片裁剪成多个,不但占用磁盘空间,也会拖慢网站性能,相当闹心! 当时也提到了解决办法: ①.关闭主题自带缩略图裁剪功能(若 ...

  6. C#设计模式总结 C#设计模式(22)——访问者模式(Vistor Pattern) C#设计模式总结 .NET Core launch.json 简介 利用Bootstrap Paginator插件和knockout.js完成分页功能 图片在线裁剪和图片上传总结 循序渐进学.Net Core Web Api开发系列【2】:利用Swagger调试WebApi

    C#设计模式总结 一. 设计原则 使用设计模式的根本原因是适应变化,提高代码复用率,使软件更具有可维护性和可扩展性.并且,在进行设计的时候,也需要遵循以下几个原则:单一职责原则.开放封闭原则.里氏代替 ...

  7. C# 图片的裁剪,两个图片合成一个图片

    图片的裁剪,两个图片合成一个图片(这是从网上摘的) /// <summary>         /// 图片裁剪,生成新图,保存在同一目录下,名字加_new,格式1.png  新图1_ne ...

  8. 第七篇、OC_图片的裁剪基于SDWebImage

    前期有段时间困扰了我很久一个问题由于工程中的图片数据抓取自不同平台,所以图片的大小尺寸不一定,而放置图片的imageView尺寸是一定的,不作任何处理的话会导致图片拉伸变形,因此找了好久解决办法,现把 ...

  9. Web自动化框架之五一套完整demo的点点滴滴(excel功能案例参数化+业务功能分层设计+mysql数据存储封装+截图+日志+测试报告+对接缺陷管理系统+自动编译部署环境+自动验证false、error案例)

    标题很大,想说的很多,不知道从那开始~~直接步入正题吧 个人也是由于公司的人员的现状和项目的特殊情况,今年年中后开始折腾web自动化这块:整这个原因很简单,就是想能让自己偷点懒.也让减轻一点同事的苦力 ...

随机推荐

  1. 创建线程的两种方式:继承Thread类和实现Runnable接口

    第一种方式:继承Thread类 步骤:1.定义类继承Thread 2.覆写Threa类的run方法. 自定义代码放在run方法中,让线程运行 3.调用线程的star方法, 该线程有两个作用:启动线程, ...

  2. SICP 习题 (1.37)解题总结

    SICP 习题 1.37是一条非常长的题目,主要讲的是无穷连分式.无穷连分式对我来说又是一个陌生的概念,于是又去百度了一番,发现无穷连分式也是一个非常有意思的话题,涉及到无理数的表达.只是我建议大家还 ...

  3. swiper实现触摸滑动

    引入文件的必要性 <link href="css/swiper.min.css" rel="stylesheet" type="text/css ...

  4. UVA 10870 - Recurrences(矩阵高速功率)

    UVA 10870 - Recurrences 题目链接 题意:f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n - 3) + ... + ad f(n - d), ...

  5. SEO要领:8文章主持技巧(两)

    续篇:搜索引擎优化要领:8条辅助技巧(一) 四.检查你的robots.txt文件 与谷歌的蜘蛛通信的经常用法是使用robots.txt文件. 这是一个文本文件.同意你告诉搜索引擎,你的站点的网页上抓取 ...

  6. Leetcode dfs Combination SumII

    Combination Sum II Total Accepted: 13710 Total Submissions: 55908My Submissions Given a collection o ...

  7. e.target 和 e.srcElement 的使用问题

    ie 下的event.srcElement从字面上可以看出来有以下关键字:事件.源(它的意思就是:当前事件的源), 我们可以调用他的各种属性就像:document.getElementById(&qu ...

  8. jquery 元素控制(附加元素/其他内容)引进和应用

    一个.在内部元素/外部附加元件 append,prepend:加入到该子元素  before,after:元素加入 html: <div id="content"> 在 ...

  9. ocp11g培训内部教材_052课堂笔记(042)_体系架构

    OCP 052 课堂笔记 目录 第一部分: Oracle体系架构... 4 第一章:实例与数据库... 4 1.Oracle 网络架构及应用环境... 4 2.Oracle 体系结构... 4 3. ...

  10. VS2012使用XListCtrl

    XListCtrl.强大ListCtrl.到现在,所有我曾经遇到过ListCtrl我们使用XListCtrl攻克. XListCtrl有什么可以支持? 变化column背景颜色.尺寸.线.制作chec ...