.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自动化这块:整这个原因很简单,就是想能让自己偷点懒.也让减轻一点同事的苦力 ...
随机推荐
- atitit.为什么技术的选择方法java超过.net有前途
atitit.为什么技术的选择方法java超过.net有前途 #----有没有法律依据不同的铜需求... 通常有开发效率,需要在稳定性.. 笔者 老哇爪 Attilax 艾龙, EMAIL:1466 ...
- Hadoop Streaming 得到mapreduce_map_input_file中遇到的问题的版本号
1.Hadoop Streaming,您可以在任务获得hadoop设置环境变量, 例如,使用awk书面map从而能获得:filename = ENVIRON["mapreduce_map_i ...
- java两个音频进入巩固期 玩的同时类似的伴奏
/** * * @param partsPaths 阵列要合成音频路径 * @param unitedFilePath 输入合并结果数组 */ public void uniteWavFile(Str ...
- springMVC3得知(五岁以下儿童)--MultiActionController
Spring为了提供一个多动作控制器,您可以使用它的几个行动统一到一个控制器,这可以放在一起功能. 多动作控制器存在在一个单独的包中--org.springframework.web.mvc.mult ...
- 【iOS开展-94】xcode6如何使用GIT以及如何添加太老项目GIT特征?
(1)对于一个新项目:如何使用GIT?在新项目的过程,例如,您可以选择下面的复选框. (2)针对老项目,加入GIT功能. --在终端.cd到项目文件夹 --然后输入git init,初始化一个.git ...
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
1.错误叙述性说明 2014-7-12 0:38:57 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplica ...
- CSS3新功能简要
1.CSS3 框架: 由 CSS3,您可以创建圆角.加入到该矩形阴影,使用图片绘制边框.例如 * border-radius -border-*-radius(top,left,right,bo ...
- 【转】细说 Form (表单)
阅读目录 开始 简单的表单,简单的处理方式 表单提交,成功控件 多提交按钮的表单 上传文件的表单 MVC Controller中多个自定义类型的传入参数 F5刷新问题并不是WebForms的错 以Aj ...
- Linux_下安装MySQL
linux下mysql 最新版安装图解教程 1.查看当前安装的linux版本 命令:lsb_release -a 如下图所示 通过上图中的数据可以看出安装的版本为RedHat5.4,所以我们需要下载R ...
- Linux报too many open files的解决方案
今天系统中有一台服务器出现异常,有时连简单的shell命令都无法执行,各种奇怪的报错,有的时候又可以成功执行 如: -bash: error while loading shared librarie ...