有什么方法把图片变圆吗

菜鸟犀利哥 2014-12-26 01:25:20
Bitmap bit = new Bitmap(80,80);
Graphics graph = Graphics.FromImage(bit);
Bitmap bit1 = new Bitmap(Server.MapPath("Image/tu4.png"));
Bitmap bit2 = new Bitmap(Server.MapPath("Image/ren.png"));
Bitmap bit3 = new Bitmap(Server.MapPath("Image/tu3.png"));
Bitmap bit4 = new Bitmap(Server.MapPath("Image/add.png"));

graph.Clear(Color.White);
graph.DrawImage(bit,0,0);
graph.DrawImage(bit1, 0, 0, 40, 40);
graph.DrawImage(bit2, 40, 40, 40, 40);
graph.DrawImage(bit3, 0, 40, 40, 40);
graph.DrawImage(bit4, 40, 0, 40, 40);
bit.Save(Server.MapPath("Image/a.jpg"));


我四张图合成放在一个大图上, 不过我像要每个小图是个园的,效果, 求大神!!
...全文
125 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
菜鸟犀利哥 2014-12-26
  • 打赏
  • 举报
回复
引用 2 楼 bdmh 的回复:
参考网上代码

private void Form1_Paint(object sender, PaintEventArgs e)
{
    string filename = "icon.png";//如果不是png类型,须转换
    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(filename);
    for (int y = 0; y < 100; y++)
    {
        for (int x = 0; x < 100; x++)
        {
            if ((x - 50) * (x - 50) + (y - 50) * (y - 50) > 50 * 50)
            {
                bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(0, 255, 255, 255));
            }
        }
    }
 
    Graphics g = CreateGraphics();
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    g.DrawImage(bitmap, new Point(50, 50));
    g.DrawEllipse(new Pen(Color.LightGray), 50, 50, 100, 100);
    g.Dispose();
}
- - 不是 网页实现,不是窗体啊
菜鸟犀利哥 2014-12-26
  • 打赏
  • 举报
回复
引用 1 楼 Z65443344 的回复:
图片没有圆的,它必须是方的 不过可以看起来是圆的 你画完计算一下,把圆外面的点变成别的颜色,或者设置成透明色,不就得了
4个叫变透明是那个方法?
bdmh 2014-12-26
  • 打赏
  • 举报
回复
参考网上代码

private void Form1_Paint(object sender, PaintEventArgs e)
{
    string filename = "icon.png";//如果不是png类型,须转换
    System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(filename);
    for (int y = 0; y < 100; y++)
    {
        for (int x = 0; x < 100; x++)
        {
            if ((x - 50) * (x - 50) + (y - 50) * (y - 50) > 50 * 50)
            {
                bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(0, 255, 255, 255));
            }
        }
    }
 
    Graphics g = CreateGraphics();
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    g.DrawImage(bitmap, new Point(50, 50));
    g.DrawEllipse(new Pen(Color.LightGray), 50, 50, 100, 100);
    g.Dispose();
}
於黾 2014-12-26
  • 打赏
  • 举报
回复
图片没有圆的,它必须是方的 不过可以看起来是圆的 你画完计算一下,把圆外面的点变成别的颜色,或者设置成透明色,不就得了

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧