.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自动化这块:整这个原因很简单,就是想能让自己偷点懒.也让减轻一点同事的苦力 ...
随机推荐
- 关于在同一母版页中使用多个CSS文件的解决方案
原文:关于在同一母版页中使用多个CSS文件的解决方案 以前都用.NET1.1没遇到这问题,现在换了2.0开始学着使用母版,结果就遇到了这个问题,在百度上一搜索才发现有不少人提出这个问题,但没找到好的解 ...
- Maven+struts2+spring4+hibernate4的环境搭建
搭建Maven+struts2+spring4+hibernate4其实并不难!但开始弄的时候还是费了我好大的力气,老是出现这样那样的错误!好了,废话不多说,开始搭建开发环境. 一.Myeclipse ...
- Apriori算法Python实现
Apriori如果数据挖掘算法的头发模式挖掘鼻祖,从60年代开始流行,该算法非常简单朴素的思维.首先挖掘长度1频繁模式,然后k=2 这些频繁模式的长度合并k频繁模式.计算它们的频繁的数目,并确保其充分 ...
- 查询oracle sql运行计划,一个非常重要的观点--dba_hist_sql_plan
该文章的作者给予了极大的帮助长老枯荣,为了表达我的谢意. 这适用于oracle db版本号oracle 10g或者更高的版本号. 之所以说这种看法是非常重要的,因为观点是有之一awrsqrpt报告没有 ...
- libmsgque官方主页
libmsgque 消息队列(MESSAGE QUEUE)库项目简析 注: 本文如果你已经有linux开发环境 请确保你使用本库时是tag版本号. target=libmsgque-1.0 本项目採用 ...
- zoj 3210 A Stack or A Queue? (数据结构水题)
A Stack or A Queue? Time Limit: 1 Second Memory Limit: 32768 KB Do you know stack and queue? ...
- Android Fragment与Activity之间的数据交换(Fragment从Activity获取数据)
Fragment与Activity之间的数据交换,通常含有3: 一.Fragment从Activity获取数据(仅本文介绍了一个第一): 两.Activity从Fragment获取数据: 三.Frag ...
- php_PHP与Mysql的连接
展示效果: 繁写: <?php echo "This is a test</br>"; echo "asdfasdfadsf"; ...
- NDMCDB数据库hang住故障分析 - cursor: pin S wait on X
问题描写叙述: 上午刚刚到办公室,就有监控人员邮件反馈,昨晚NDMCDB407数据库被重新启动过,让我分析一下数据库重新启动的原因.因为昨晚业务有版本号上线,所以短信警告关闭了,所以没有短信下发到我手 ...
- 微信原生支付 Native扫码支付( V3.3.7 版本)
原文:微信原生支付 Native扫码支付( V3.3.7 版本) [尊重别人的劳动成果,转载请注明出处:一缕晨光工作室,www.wispdawn.com] 前言 辛苦研究三天,遇到各种困难,最终还是克 ...