博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WindowsPhone8中实现圆形图片的生成显示
阅读量:7171 次
发布时间:2019-06-29

本文共 1083 字,大约阅读时间需要 3 分钟。

原文

很多软件中(比如QQ)用到了许多圆形图片,作为用户头像等等,原始图片往往是方形的,那么怎么样将方形的图片显示成圆形呢?

一种方法是当背景为固定纯色的时候,可以使用同背景色的边框遮罩,这种方法适用性小,这里不再赘述。

我的做法是使用ArcSegment的功能来实现圆形图片的显示,ArcSegment派生自PathSegment,“~派生自 PathSegment 的类(例如 ArcSegment、BezierSegment 和 LineSegment),表示特定类型的几何图形段。”

思路来源于这篇文章:

主要实现代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
PathGeometry pg =
new
PathGeometry();
 
PathFigure pf1 =
new
PathFigure();
pf1.StartPoint =
new
Point(0, height / 2);
pf1.Segments.Add(
new
ArcSegment()
{
    
IsLargeArc =
true
,
    
Point =
new
Point(width, height / 2),
    
Size =
new
Size(width / 4, height / 4),
});
pg.Figures.Add(pf1);
 
PathFigure pf2 =
new
PathFigure();
pf2.StartPoint =
new
Point(0, height / 2);
pf2.Segments.Add(
new
ArcSegment()
{
    
SweepDirection = SweepDirection.Clockwise,
    
IsLargeArc =
true
,
    
Point =
new
Point(width, height / 2),
    
Size =
new
Size(width / 4, height / 4),
});
pg.Figures.Add(pf2);
 
image.Clip = pg;

封装好的一个圆形图片控件:

 

使用方法

1:添加CircleImage.dll引用

2:xmlns:CircleImage="clr-namespace:CircleImage;assembly=CircleImage"

3:<CircleImage:CircleImage Source="test.jpg" Width="400" Height="400"/>

转载地址:http://zrfzm.baihongyu.com/

你可能感兴趣的文章
XGPush集成(信鸽集成)demo
查看>>
结构化异常处理 读书笔记
查看>>
性能优化3--数据库优化
查看>>
Deep Q-Network 学习笔记(五)—— 改进③:Prioritized Replay 算法
查看>>
Dancing Links
查看>>
WPF绘图性能问题
查看>>
word-break:break-all和word-wrap:break-word的区别
查看>>
python基础===tkinter学习链接
查看>>
实验五 存储管理实验
查看>>
【开源一个小工具】一键将网页内容推送到Kindle
查看>>
Ajax请求中的异步与同步,需要注意的地方。
查看>>
Android ImageButton图像灰色边框
查看>>
Luogu3242:[HNOI2015]接水果
查看>>
JavaScript知识点回顾
查看>>
关于浏览器兼容处理的几种方式
查看>>
第一个Asp.net小项目,主页写了下后台代码
查看>>
(推荐使用)SpringMVC注解,基本配置
查看>>
ORA-12547: TNS:lost contact+oracle 开启监听失败
查看>>
软件工程结对作业01(四则运算网页版)
查看>>
解决开机自动调用脚本失败的问题
查看>>