e582. Drawing with Color

public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
    
        // Use a predefined color
        g2d.setColor(Color.red);
        // Draw shapes...; see e586 Drawing Simple Shapes
    
        // Use a custom color
        int red = 230;
        int green = 45;
        int blue = 67;
        g2d.setColor(new Color(red, green, blue));
        // Draw shapes...; see e586 Drawing Simple Shapes
    }

 

Related Examples
namespace CSVDataPlotter { partial class MainForm { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.btnLoad = new System.Windows.Forms.Button(); this.dataTimer = new System.Windows.Forms.Timer(this.components); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); this.SuspendLayout(); // // chart1 // chartArea1.Name = "MainArea"; this.chart1.ChartAreas.Add(chartArea1); legend1.Name = "Legend1"; this.chart1.Legends.Add(legend1); this.chart1.Location = new System.Drawing.Point(12, 50); this.chart1.Name = "chart1"; this.chart1.Size = new System.Drawing.Size(776, 350); this.chart1.TabIndex = 0; this.chart1.Text = "chart1"; // // btnLoad // this.btnLoad.Font = new System.Drawing.Font("Microsoft YaHei", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnLoad.Location = new System.Drawing.Point(12, 12); this.btnLoad.Name = "btnLoad"; this.btnLoad.Size = new System.Drawing.Size(150, 32); this.btnLoad.TabIndex = 1; this.btnLoad.Text = "加载CSV文件"; this.btnLoad.UseVisualStyleBackColor = true; this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); // // dataTimer // this.dataTimer.Interval = 5000; this.dataTimer.Tick += new System.EventHandler(this.DataTimer_Tick); // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.btnLoad); this.Controls.Add(this.chart1); this.Name = "MainForm"; this.Text = "CSV数据图表"; this.Load += new System.EventHandler(this.MainForm_Load); ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.DataVisualization.Charting.Chart chart1; private System.Windows.Forms.Button btnLoad; private System.Windows.Forms.Timer dataTimer; } }严重性 代码 说明 项目 文件 行 禁止显示状态 错误 CS1061 “MainForm”未包含“MainForm_Load”的定义,并且找不到可接受第一个“MainForm”类型参数的可访问扩展方法“MainForm_Load”(是否缺少 using 指令或程序集引用?) CSVDataPlotter D:\software\DLL\CSVDataPlotter\CSVDataPlotter\Form1.Designer.cs 78 活动
08-09
绘制关键点时出错: ‘NormalizedLandmark’ object has no attribute 'HasField’import cv2 import mediapipe as mp from datetime import datetime def add_overlay(frame, text, position, color=(0, 255, 0)): """添加文本叠加层""" cv2.putText(frame, text, position, cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2) def show_frame(frame, window_name='Pose Detection'): if frame is None or frame.size == 0: print("警告:收到空帧,跳过显示") return False """显示帧并处理键盘事件""" cv2.imshow(window_name, frame) key = cv2.waitKey(1) if key == ord('q') or key == 27: print("检测到退出指令") return True elif cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE) < 1: print("窗口被手动关闭") return True return False class ResultVisualizer: def __init__(self): self._pose_landmark_drawing_spec = mp.solutions.drawing_utils.DrawingSpec( color=(0, 255, 0), thickness=2, circle_radius=2) self._pose_connection_drawing_spec = mp.solutions.drawing_utils.DrawingSpec( color=(0, 0, 255), thickness=2) self._last_time = cv2.getTickCount() self._frame_count = 0 def draw_landmarks(self, frame, landmarks): try: # 检查 landmarks 是否有 landmark 属性 if hasattr(landmarks, 'landmark'): mp.solutions.drawing_utils.draw_landmarks( frame, landmarks, mp.solutions.pose.POSE_CONNECTIONS, self._pose_landmark_drawing_spec, self._pose_connection_drawing_spec) return frame except Exception as e: print(f"绘制关键点时出错: {str(e)}") return frame def calculate_fps(self): current_time = cv2.getTickCount() elapsed_time = (current_time - self._last_time) / cv2.getTickFrequency() self._frame_count += 1 if elapsed_time > 1: fps = self._frame_count / elapsed_time self._last_time = current_time self._frame_count = 0 return fps return 0
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值