效果:

        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# 提供两种切割圆形图片的方式的更多相关文章

  1. React Native两种加载图片的方式

    1 加载网络图片 通过uri就可以加载网络图片 <Image source={{uri:'http://facebook.github.io/react/img/logo_og.png'}} s ...

  2. iOS 两种不同的图片无限轮播

    代码地址如下:http://www.demodashi.com/demo/11608.html 前记 其实想写这个关于无限轮播的记录已经很久很久了,只是没什么时间,这只是一个借口,正如:时间就像海绵, ...

  3. reportConfig.xml两种数据源连接的配置方式

     在reportConfig.xml配置文件中,我们提供了两种数据源连接的配置方式,分别如下: 1.jndi数据源配置(即:在dataSource中配置) 此配置适用于在j2ee的服务器中配置了j ...

  4. 流式思想概述和两种获取Stream流的方式

    流式思想概述 整体来看,流式思想类似于工厂车间的生产流水线 当需要对多个元素进行操作(特别是多步操作)的时候,考虑到性能及便利性,我们应该首先拼好一个模型步骤方案,然后再按照方法去执行他 这张图中展示 ...

  5. KbmMW两种查询结果集通讯方式

    KbmMW本身可以用QueryService的方式进行远程数据查询,但是SmpileService同样具有很强的扩展性可以实现数据查询,下面展示两种基于SmpileService的远程数据查询方法,其 ...

  6. 两种不同png图片的在项目中的运用

    png图片主要分为两种 png-8和png-24. PNG8和PNG24后面的数字则是代表这种PNG格式最多可以索引和存储的颜色值.”8″代表2的8次方也就是256色,而24则代表2的24次方大概有1 ...

  7. ios的UIImage的两种不同的图片加载方式 tom猫

    在ios的UI交互设计时,对图片的处理是难免的:不同的处理方式会对内存有不同的影响: ********************************************************* ...

  8. SpringMVC提供两种校验机制

    本文不讲如何使用SpringMVC提供的两种校验机制,只是简单的说明一下其中的差别而已: 1.创建一个Bean,在Bean的属性中添加校验信息,通过配置LocalValidatorFactoryBea ...

  9. (转)TestNG框架提供两种传入参数的方法:

    1.从testng.xml传入参数. 如果参数是一些简单的值,可以直接在testng.xml中定义.这也是最常用的一种. 可以在测试用例中给参数一个默认值.这样,即使在xml文件中没有这个变量,你的测 ...

随机推荐

  1. python 列表转换成字符串

    用字符串的 join 方法: li = ['a', 'b', 'c', 'd'] s = ''.join(li) print(s) abcd 用字符串的占位符替换 li = ['a', 'b', 'c ...

  2. grunt 一个目录下所有的js文件压缩 配置收藏

    module.exports = function(grunt){ // 项目配置 grunt.initConfig({ pkg: grunt.file.readJSON('package.json' ...

  3. MSSQL 死锁查询

    SELECT SYS.DM_EXEC_REQUESTS.SESSION_ID,TEXT AS '执行SQL',CLIENT_NET_ADDRESS AS '请求IP',SYS.DM_EXEC_CONN ...

  4. 怎样去除织梦版权信息中的Power by DedeCms

    用织梦建站时,网站底部调用的版权信息最后总会多出一个Power by DedeCms链接,此链接是织梦系统中默认的指向织梦官网的外链.本文就介绍两种去除这个外链的方法. 1.为什么要去除Power b ...

  5. 制作IOS企业版App网页扫描二维码下载安装

    有时候我们需要在XX网站的主页上去扫描二维码下载,那么ios开发中如何做到这一点呢. 我给大家解答一下,这也是在最近工作中用到的部分,在网上了解了一些. 下面给大家分解一下步骤: 1.Plist 和 ...

  6. About_Return

    返回值:return return 表示从被调函数返回到主调函数继续执行,返回时可附带一个返回值,由return后面的参数指定. return通常是必要的,因为函数调用的时候计算结果通常是通过返回值带 ...

  7. ECMAScript 6(ES6)有什么新东西

    你可能已经听说过ECMAScript 6,JavaScript的下一个版本,它有一些非常棒的新功能.这些功能略微复杂,在简单的脚本和复杂的应用中都可以使用.在这篇文章中,我们将挑选一些ES6的功能进行 ...

  8. #20145205 《Java程序设计》第3周学习总结

    教材学习内容总结 1.java中的浮点数具体是由分数进行表示的,所以在有些时候,看起来很简单的基本运算,运行结果会让人很是不理解,原因是分数有时表示浮点数时无法完全恰好表示,可能会出现无限循环的情况. ...

  9. hibernate学习(8)——事务.连接池.锁 相关设置

    1.整合c3p0(连接池) 步骤一:导入c3p0 jar包 步骤二:hibernate.cfg.xml 配置 hibernate.connection.provider_class org.hiber ...

  10. PARALLEL PROCESSING

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION