【问题标题】:How to get the pixel data in the image box under the cursor?如何获取光标下图像框中的像素数据?
【发布时间】:2012-09-24 17:16:03
【问题描述】:

这里是网络摄像头程序,它可以使用 void ProcessFrame 循环显示图像 如何使用以下代码获取光标下的图像框内的像素数据?

这是我从网站上捕获的代码。非常感谢您的帮助

enter code here
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using System.Threading; 
namespace MyOpenCV
{
public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

private Capture _capture;
private bool _captureInProgress;


private void ProcessFrame(object sender, EventArgs arg)
{
    Image<Bgr, Byte> frame = _capture.QueryFrame();  
    captureImageBox1.Image = frame;
}

private void captureButton_Click_1(object sender, EventArgs e)
{
    #region if capture is not created, create it now
    if (_capture == null)
    {
        try
        {
            _capture = new Capture();
        }
        catch (NullReferenceException excpt)
        {
            MessageBox.Show(excpt.Message);
        }
    }
    #endregion

    if (_capture != null)
    {
        if (_captureInProgress)
        {  //stop the capture 
            Application.Idle -= new EventHandler(ProcessFrame);
            captureButton.Text = "Start Capture";
        }
        else
        {
            //start the capture 
            captureButton.Text = "Stop";
            Application.Idle += new EventHandler(ProcessFrame);
        }

        _captureInProgress = !_captureInProgress;
    }
}

【问题讨论】:

  • 不确定我理解你的意思吗?你想达到什么目的?
  • 我想在这段代码的基础上..添加一个可以显示光标下像素数据的新函数
  • 你是什么意思,基于这段代码?

标签: c#


【解决方案1】:

试试这个:

private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            var bmp = (Bitmap) pictureBox1.Image;
            var color = bmp.GetPixel(e.X, e.Y);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    相关资源
    最近更新 更多