C# 提供两种切割圆形图片的方式
效果:

private void Form1_Load(object sender, EventArgs e)
{
string file =System.IO.Path.Combine(Environment.CurrentDirectory, @"11.jpg");
try
{
Image i = new Bitmap(file);
pbO.Image = i; pbD1.Image = WayOne(file);
pbD2.Image = WayTwo(file); pbS1.Image = WaySOne(file);
pbS2.Image = WaySTwo(file); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private Bitmap WayOne(string file)
{
using (Image i = new Bitmap(file))
{
Bitmap b = new Bitmap(i.Width, i.Height);
using (Graphics g = Graphics.FromImage(b))
{
g.FillEllipse(new TextureBrush(i), , , i.Width, i.Height);
}
return b;
}
}
private Bitmap WayTwo(string file)
{
using (Image i = new Bitmap(file))
{
Bitmap b = new Bitmap(i.Width, i.Height);
using (Graphics g = Graphics.FromImage(b))
{
g.DrawImage(i, , , b.Width, b.Height);
int r = Math.Min(b.Width, b.Height) / ;
PointF c = new PointF(b.Width / 2.0F, b.Height / 2.0F);
for (int h = ; h < b.Height; h++)
for (int w = ; w < b.Width; w++)
if ((int)Math.Pow(r, ) < ((int)Math.Pow(w * 1.0 - c.X, ) + (int)Math.Pow(h * 1.0 - c.Y, )))
{
b.SetPixel(w, h, Color.Transparent);
}
}
return b;
}
} private Bitmap WaySOne(string file)
{
using (Image i = new Bitmap(file))
{
Bitmap b = new Bitmap(i.Width, i.Height);
using (Graphics g = Graphics.FromImage(b))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
using (System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Alternate))
{
p.AddEllipse(, , i.Width, i.Height);
g.FillPath(new TextureBrush(i), p);
}
//g.FillEllipse(new TextureBrush(i), 0, 0, i.Width, i.Height);
}
return b;
}
}
private Bitmap WaySTwo(string file)
{
using (Image i = new Bitmap(file))
{
Bitmap b = new Bitmap(i.Width, i.Height);
using (Graphics g = Graphics.FromImage(b))
{
g.DrawImage(i, , , b.Width, b.Height);
int r = Math.Min(b.Width, b.Height) / ;
PointF c = new PointF(b.Width / 2.0F, b.Height / 2.0F);
for (int h = ; h < b.Height; h++)
for (int w = ; w < b.Width; w++)
if ((int)Math.Pow(r, ) < ((int)Math.Pow(w * 1.0 - c.X, ) + (int)Math.Pow(h * 1.0 - c.Y, )))
{
b.SetPixel(w, h, Color.Transparent);
}
//画背景色圆
using (Pen p = new Pen(System.Drawing.SystemColors.Control))
g.DrawEllipse(p, , , b.Width, b.Height);
}
return b;
}
}
C# 提供两种切割圆形图片的方式的更多相关文章
- React Native两种加载图片的方式
1 加载网络图片 通过uri就可以加载网络图片 <Image source={{uri:'http://facebook.github.io/react/img/logo_og.png'}} s ...
- iOS 两种不同的图片无限轮播
代码地址如下:http://www.demodashi.com/demo/11608.html 前记 其实想写这个关于无限轮播的记录已经很久很久了,只是没什么时间,这只是一个借口,正如:时间就像海绵, ...
- reportConfig.xml两种数据源连接的配置方式
在reportConfig.xml配置文件中,我们提供了两种数据源连接的配置方式,分别如下: 1.jndi数据源配置(即:在dataSource中配置) 此配置适用于在j2ee的服务器中配置了j ...
- 流式思想概述和两种获取Stream流的方式
流式思想概述 整体来看,流式思想类似于工厂车间的生产流水线 当需要对多个元素进行操作(特别是多步操作)的时候,考虑到性能及便利性,我们应该首先拼好一个模型步骤方案,然后再按照方法去执行他 这张图中展示 ...
- KbmMW两种查询结果集通讯方式
KbmMW本身可以用QueryService的方式进行远程数据查询,但是SmpileService同样具有很强的扩展性可以实现数据查询,下面展示两种基于SmpileService的远程数据查询方法,其 ...
- 两种不同png图片的在项目中的运用
png图片主要分为两种 png-8和png-24. PNG8和PNG24后面的数字则是代表这种PNG格式最多可以索引和存储的颜色值.”8″代表2的8次方也就是256色,而24则代表2的24次方大概有1 ...
- ios的UIImage的两种不同的图片加载方式 tom猫
在ios的UI交互设计时,对图片的处理是难免的:不同的处理方式会对内存有不同的影响: ********************************************************* ...
- SpringMVC提供两种校验机制
本文不讲如何使用SpringMVC提供的两种校验机制,只是简单的说明一下其中的差别而已: 1.创建一个Bean,在Bean的属性中添加校验信息,通过配置LocalValidatorFactoryBea ...
- (转)TestNG框架提供两种传入参数的方法:
1.从testng.xml传入参数. 如果参数是一些简单的值,可以直接在testng.xml中定义.这也是最常用的一种. 可以在测试用例中给参数一个默认值.这样,即使在xml文件中没有这个变量,你的测 ...
随机推荐
- mysql导入导出,及错误记录
进入mysql的bin目录,如果mysql的bin添加了环境变量则不用. 导出,不指定编码则默认为:utf8mb4.: mysqldump -u root -h 127.0.0.1 -P 3307 - ...
- 用介个新的blog咯..
之前csdn实在是太卡了.. 只要一写比较长的blog就卡的要死.. 转过来这吧,比较好吧.. 原blog地址 啊为啥域名叫darklove呢.. 这是很久之前创建的.. 简单来说是一个和clearl ...
- dbflow 批量 增删查改
@ModelContainer @Table(database = DemoDatabase.class) class Person extends BaseModel implements Seri ...
- myeclipse2014
myeclipse 2014-GA offline 迅雷下载 http://downloads.myeclipseide.com/downloads/products/eworkbench/201 ...
- Android入门(九):CheckBox多选清单和ScrollView滚动条
字符串资源文件strings.xml: <resources> <string name="hello">主类main</string> < ...
- php递归获取顶级父类id
php递归获取顶级父类id function get_top_parentid($id){ $r = M('navclass')->where('id = '.$id)->field('i ...
- ArrayList实现删除重复元素(元素不是对象类型的情况)
package 集合; import java.util.ArrayList;import java.util.Iterator; /* * 去除ArrayList里面的重复元素 * * */pub ...
- javascript面向对象(二):构造函数的继承
本文来自阮一峰 这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例. 今天要介绍的是,对象之间的"继承"的五种方法. 比如,现在有 ...
- C# TransactionScope 使用
注意: Windows 服务中,开启Distributed Transaction Coordinator 服务. using (var scope = new TransactionScope()) ...
- 自动爬取ZiMuZu的内容发布到Wordpress
先说一下大致的步骤. 首先需要模拟浏览器登录网站才能看到相应电影信息, 然后通过正则表达式从网页源代码中筛选出所需要的电影, 最后通过python-wordpress-xmlrpc将信息逐条发布到Wo ...