/// <summary>
/// 圆形图处理
/// </summary>
/// <param name="file">需要进行操作的图片</param>
/// <param name="size">裁剪成格式(正方形size)</param>
/// <returns></returns>
public Bitmap CirclePhoto(Image file, int size)
{
using (Image i = file)
{
Bitmap b = new Bitmap(size, size);
using (Graphics g = Graphics.FromImage(b))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawImage(i, 0, 0, b.Width, b.Height);
int r = Math.Min(b.Width, b.Height) / 2;
PointF c = new PointF(b.Width / 2.0F, b.Height / 2.0F);
for (int h = 0; h < b.Height; h++)
for (int w = 0; w < b.Width; w++)
if ((int)Math.Pow(r, 2) < ((int)Math.Pow(w * 1.0 - c.X, 2) + (int)Math.Pow(h * 1.0 - c.Y, 2)))
{
b.SetPixel(w, h, Color.Transparent);
}
//画背景色圆
using (Pen p = new Pen(System.Drawing.SystemColors.Control))
g.DrawEllipse(p, 0, 0, b.Width, b.Height);
}
return b;
}
}
/// 圆形图处理
/// </summary>
/// <param name="file">需要进行操作的图片</param>
/// <param name="size">裁剪成格式(正方形size)</param>
/// <returns></returns>
public Bitmap CirclePhoto(Image file, int size)
{
using (Image i = file)
{
Bitmap b = new Bitmap(size, size);
using (Graphics g = Graphics.FromImage(b))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawImage(i, 0, 0, b.Width, b.Height);
int r = Math.Min(b.Width, b.Height) / 2;
PointF c = new PointF(b.Width / 2.0F, b.Height / 2.0F);
for (int h = 0; h < b.Height; h++)
for (int w = 0; w < b.Width; w++)
if ((int)Math.Pow(r, 2) < ((int)Math.Pow(w * 1.0 - c.X, 2) + (int)Math.Pow(h * 1.0 - c.Y, 2)))
{
b.SetPixel(w, h, Color.Transparent);
}
//画背景色圆
using (Pen p = new Pen(System.Drawing.SystemColors.Control))
g.DrawEllipse(p, 0, 0, b.Width, b.Height);
}
return b;
}
}