.net图片自动裁剪白边函数案例
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图片自动裁剪白边函数案例的更多相关文章
- 如何安装nginx_lua_module模块,升级nginx,nginx-lua-fastdfs-GraphicsMagick动态生成缩略图,实现图片自动裁剪缩放
如何安装nginx_lua_module模块,升级nginx,nginx-lua-fastdfs-GraphicsMagick动态生成缩略图,实现图片自动裁剪缩放 参考网站:nginx-lua-fas ...
- Tengine + Lua + GraphicsMagick 实现图片自动裁剪/缩放
http://my.oschina.net/eduosi/blog/169606
- 【转载】如何让图片按比例响应式缩放、并自动裁剪的css技巧
原文: http://blog.csdn.net/oulihong123/article/details/54601030 响应式网站.移动端页面在DIV CSS布局中对于图片列表或图片排版时, 如果 ...
- C#开发自动照片(图片)裁剪(缩放)工具
1.需求分析 用winform窗体程序,开发一个能够自动.批量对图片进行缩放和裁剪的程序. 原本想直接从网上找类型的工具直接用,但是无奈现在网上能找到的工具,要么不能用,要么就是很 恶心的下载完后还有 ...
- 一行代码彻底禁用WordPress缩略图自动裁剪功能
记得在博客分享七牛缩略图教程的时候,提到过 WordPress 默认会将上传的图片裁剪成多个,不但占用磁盘空间,也会拖慢网站性能,相当闹心! 当时也提到了解决办法: ①.关闭主题自带缩略图裁剪功能(若 ...
- C#设计模式总结 C#设计模式(22)——访问者模式(Vistor Pattern) C#设计模式总结 .NET Core launch.json 简介 利用Bootstrap Paginator插件和knockout.js完成分页功能 图片在线裁剪和图片上传总结 循序渐进学.Net Core Web Api开发系列【2】:利用Swagger调试WebApi
C#设计模式总结 一. 设计原则 使用设计模式的根本原因是适应变化,提高代码复用率,使软件更具有可维护性和可扩展性.并且,在进行设计的时候,也需要遵循以下几个原则:单一职责原则.开放封闭原则.里氏代替 ...
- C# 图片的裁剪,两个图片合成一个图片
图片的裁剪,两个图片合成一个图片(这是从网上摘的) /// <summary> /// 图片裁剪,生成新图,保存在同一目录下,名字加_new,格式1.png 新图1_ne ...
- 第七篇、OC_图片的裁剪基于SDWebImage
前期有段时间困扰了我很久一个问题由于工程中的图片数据抓取自不同平台,所以图片的大小尺寸不一定,而放置图片的imageView尺寸是一定的,不作任何处理的话会导致图片拉伸变形,因此找了好久解决办法,现把 ...
- Web自动化框架之五一套完整demo的点点滴滴(excel功能案例参数化+业务功能分层设计+mysql数据存储封装+截图+日志+测试报告+对接缺陷管理系统+自动编译部署环境+自动验证false、error案例)
标题很大,想说的很多,不知道从那开始~~直接步入正题吧 个人也是由于公司的人员的现状和项目的特殊情况,今年年中后开始折腾web自动化这块:整这个原因很简单,就是想能让自己偷点懒.也让减轻一点同事的苦力 ...
随机推荐
- opencv在arm和x86在移植
一个.开发环境 操作系统:fedora14 Opencv版本号:2.0 Qt版本号:4.7 arm:mini6410 交叉编译工具:arm-linux-gcc-4.5.1 二.安装与配置 Linux系 ...
- Rust这个新的语言
Rust这个新的语言 Rust初步(七):格式化 摘要: 在Rust中,如果要进行屏幕输出,或者写入到文件中,需要对数据进行格式化.这一篇总结一下它所支持的几种格式化方式. 这篇文章参考了以下官方文档 ...
- 左右GNU Linux企业加密文件系统 eCryptfs简介
/********************************************************************* * Author : Samson * Date ...
- unity 编辑器和插件生产(四.2)
上次 我们告诉编辑器制作,如何将图像加载到现场,如今 我们要告诉下.怎么样 制造UIButton以及UIimage交换. 阿土. 进入专题. 首先,我们要明白 unity机制.button属性等. 首 ...
- Codeforces 490F. Treeland Tour 暴力+LIS
枚举根+dfs 它可以活 , 我不知道有什么解决的办法是积极的 ...... F. Treeland Tour time limit per test 5 seconds memory limit p ...
- IE8升级新版Flash Player ActiveX14导致的discuz图片附件无法上传 解决方法
架不住sb adobe的频繁升级提示,手欠升级到了了flash player 14,结果IE8下全部discuz论坛中都无法看到上传图片的button了 没办法,遇到问题就解决吧 刚好在解决IE11遇 ...
- 从头开始学JavaScript (十一)——Object类型
原文:从头开始学JavaScript (十一)--Object类型 一.object类型 一个object就是一系列属性的集合,一个属性包含一个名字(属性名)和一个值(属性值). object对于在应 ...
- Android开发手册 (Android的手工教程MtAndroid开发手册)
放出版许可协议 1.0 或者更新版本号. 未经版权全部者明白授权,禁止发行本文档及其被实质上改动的版本号. 未经版权全部者事先授权.禁止将此作品及其衍生作品以标准(纸质)书籍形式发行. 假设有兴趣再 ...
- SQL 把表中字段存储的逗号隔开内容转换成列表形式
原文:[原创]SQL 把表中字段存储的逗号隔开内容转换成列表形式 我们日常开发中,不管是表设计问题抑或是其他什么原因,或多或少都会遇到一张表中有一个字段存储的内容是用逗号隔开的列表. 具体效果如下图: ...
- 部署中遇到的问题-UWSGI(一)
假设uwsgi错误中提示 *** no app loaded. going in full dynamic mode *** 运行 [plain] view plaincopy aptitude in ...