c# - 如何用位图C#创建圆

标签 c# bitmap

你好,如何用位图画一个圆。也就是说,我需要获取圆的图像,用它来画一些东西。

最佳答案

为此目的使用ColorTranslator.FromHtml

这将为您提供相应的System.Drawing.Color:

using (Bitmap btm = new Bitmap(25, 30))
{
   using (Graphics grf = Graphics.FromImage(btm))
   {
      using (Brush brsh = new SolidBrush(ColorTranslator.FromHtml("#ff00ffff")))
      {
         grf.FillEllipse(brsh, 0, 0, 19, 19);
      }
   }
}

或引用代码:

Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

Graphics g = Graphics.FromImage(bmp);

Pen blackPen = new Pen(Color.Black);

int x = pictureBox1.Width/4;

int y = pictureBox1.Height/4;

int width = pictureBox1.Width / 2;

int height = pictureBox1.Height / 2;

int diameter = Math.Min(width, height);

g.DrawEllipse(blackPen, x, y, diameter, diameter);

pictureBox1.Image = bmp;

If the PictureBox already contains a bitmap, replace the first and second lines with:

Graphics g = Graphics.FromImage(pictureBox1.Image);

引用链接:

http://www.c-sharpcorner.com/Forums/Thread/30986/

希望它有帮助。

关于c# - 如何用位图C#创建圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16727802/

相关文章:

c# - C# 和 Python 中的 int 是一回事吗?

c# - 将位图转换为字节数组

java - Android 位图有时返回 null

c# - 从父对象调用方法 C# Unity3d

c# - 如何在正则表达式中留出空间?

android - 如何使用位图作为通知图标

c# - 为 Format32bppArgb 设置 Alpha 值

android - 处理大型位图

c# - 告诉 resharper 使用 string.Format 在 C# 中生成 ToString?

c# - Async WebClient 不是真正的异步?