效果:

        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. Page-encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)

    org.apache.jasper.JasperException:xxx.jsp(1,1) Page-encoding specified in XML prolog (UTF-8) is diff ...

  2. 【原】iOS学习之UIApplication及其代理

    1. 什么是UIApplication UIApplication 对象是应用程序的象征,不能手动创建,不能 alloc init,一个应用程序只允许 一个 . 每个应用都有自己的 UIApplica ...

  3. hibernate的@EmbeddedId嵌入式主键详解

    一.前言 在我们的日常开发中,有时候会用到数据库进行设计的时候,采用了复合主键来来保证唯一性,下面介绍一下采用hibernate的@EmbeddedId嵌入式主键. 二.说明 设计一个学生类,包含了三 ...

  4. C# Winform 中如何实现音乐播放和视频播放

    C#  Winform 中如何实现音乐播放和视频播放 namespace WindowsFormsApplication1 { public partial class Form2 : Form { ...

  5. Javascript初学篇章_5(对象)

    对象 Javascript是一种面向对象的语言,因此可以使用面向对象的思想来进行javascript程序设计对象就是由一些彼此相关的属性和方法集合在一起而构成的一个数据实体.举个例子,一只猫是个对象, ...

  6. BSBuDeJie_03

    一 快速登录 1 改变状态栏的style - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightConte ...

  7. css 温故而知新 定位(position)与权限(z-index)

    1.进行定位(position)的元素的权限(z-index)永远比没有定位的高. 2.如果两个元素都定位了,无论是相对定位还是绝对定位.他们的权限都是等权的. 3.两个相同定位的元素,除了z-ind ...

  8. gojs绘流程图

    引用:http://www.tuicool.com/articles/eEruaqu http://www.open-open.com/lib/view/open1435023502544.html ...

  9. 【emWin】例程二:显示“hello,world”

    实验指导书及代码包下载: http://pan.baidu.com/s/1c1Csx48

  10. elasticsearch运维实战之2 - 系统性能调优

    elasticsearch性能调优 集群规划 独立的master节点,不存储数据, 数量不少于2 数据节点(Data Node) 查询节点(Query Node),起到负载均衡的作用 Linux系统参 ...