圆形图片框 [英] circle shaped picture box
本文介绍了圆形图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的先生,
我想在c#中创建圆形图片框。可以画出图片框。
我该怎么办。
Dear sir,
I want to create circular picture box in c#.Can it be possible to draw picture box.
how can i do.
推荐答案
最简单的方法是设置区域:
The easiest way is to set the Region:
myPictureBox.Image = Image.FromFile(@"D:\Temp\MyPic.jpg");
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(myPictureBox.DisplayRectangle);
myPictureBox.Region = new Region(gp);
我做了这个控制来移除边缘上的像素
I did this control to remove the pixels on the edges
public class CirclePictureBox : PictureBox
{
public CirclePictureBox ()
{
}
protected override void OnPaint(PaintEventArgs e)
{
System.Drawing.Brush brushImege;
try
{
Bitmap Imagem = new Bitmap(this.Image);
//get images of the same size as control
Imagem = new Bitmap(Imagem, new Size(this.Width - 1, this.Height - 1));
brushImege = new TextureBrush(Imagem);
}
catch
{
Bitmap Imagem = new Bitmap(this.Width - 1, this.Height - 1, PixelFormat.Format24bppRgb);
using (Graphics grp = Graphics.FromImage(Imagem))
{
grp.FillRectangle(
Brushes.White, 0, 0, this.Width - 1, this.Height - 1);
Imagem = new Bitmap(this.Width - 1, this.Height - 1, grp);
}
brushImege = new TextureBrush(Imagem);
}
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, this.Width - 1, this.Height - 1);
e.Graphics.FillPath(brushImege, path);
e.Graphics.DrawPath(Pens.Black, path);
}
}
这篇关于圆形图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文