如何用鼠标点击在picturebox的图像上做标记

在这里插入图片描述
鼠标点击图像,在点击处画一个圆。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace PictureDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            //得到鼠标相对于pictureBox左上角的位置
            Point p1=pictureBox1.PointToClient(Control.MousePosition);
 
 
            Image imageBmp = pictureBox1.Image;
            using (Graphics g = Graphics.FromImage(imageBmp))
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;         //抗锯齿
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;   //高质量
                g.InterpolationMode = InterpolationMode.High;      //差值算法
 
                Color penColor = Color.Green;
                Pen pens = new Pen(penColor, 1);                //定义画笔(线条)
                Brush brushs = new SolidBrush(penColor);        //定义画刷(填充)
                g.DrawEllipse(pens, p1.X, p1.Y, 50, 50);//画圆弧线条
                g.FillEllipse(brushs, p1.X, p1.Y, 50, 50);//填充圆弧
            }
            pictureBox1.Image = imageBmp;
 
                        
        }
    }
}
 
 

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-13 11:06:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-13 11:06:06       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-13 11:06:06       82 阅读
  4. Python语言-面向对象

    2024-05-13 11:06:06       91 阅读

热门阅读

  1. Python小程序 - 文件处理1(使用AI工具)

    2024-05-13 11:06:06       34 阅读
  2. 规则引擎drools Part5

    2024-05-13 11:06:06       36 阅读
  3. 开发一款抓大鹅游戏

    2024-05-13 11:06:06       49 阅读
  4. Debug: Pytorch dataloaders OSError: Bad file descriptor

    2024-05-13 11:06:06       37 阅读
  5. leetcode题目7

    2024-05-13 11:06:06       34 阅读
  6. 【二叉树算法题记录】404. 左叶子之和

    2024-05-13 11:06:06       39 阅读
  7. 安卓LeakCanary研究

    2024-05-13 11:06:06       42 阅读
  8. SQLite 语法大全

    2024-05-13 11:06:06       98 阅读
  9. codeforce#939 (div2) 题解

    2024-05-13 11:06:06       146 阅读
  10. 什么是结对编程?

    2024-05-13 11:06:06       36 阅读
  11. Caffe: Convolutional Architecture for Fast Feature Embedding

    2024-05-13 11:06:06       35 阅读
  12. Docker 部署Redis

    2024-05-13 11:06:06       37 阅读