【问题标题】:Value height image on mouseover bigger than image height鼠标悬停时的值高度图像大于图像高度
【发布时间】:2013-08-03 06:11:48
【问题描述】:
        if (picture != null)
        {
            Int32 h = picture.Height;
            Int32 w = picture.Width;
            Int32 R = picture.GetPixel(e.X, e.Y).R;
            Int32 G = picture.GetPixel(e.X, e.Y).G;
            Int32 B = picture.GetPixel(e.X, e.Y).B;
            lbPixelValue.Text = "R:"+R+ " G:"+G+ " B:"+B;
            lbCoordinates.Text = String.Format("X: {0}; Y: {1}", e.X, e.Y);

使用上面的代码,我尝试从图片框上的鼠标获取像素值。

此代码有时运行正常,但有时代码错误:

parameter must to be positive and < height

错误:Int32 R = picture.GetPixel(e.X, e.Y).R;

我尝试调试,问题是Y > image.height

有什么问题所以我可以得到图片的Y > height

我该如何解决?

【问题讨论】:

    标签: c# image height mouse processing


    【解决方案1】:

    我认为当图片框大于图像时会发生这种情况。 试试这个:

    Int32 h = picture.Height;
    Int32 w = picture.Width;
    if (e.X < w && e.Y < h)
    {
        Int32 R = picture.GetPixel(e.X, e.Y).R;
        Int32 G = picture.GetPixel(e.X, e.Y).G;
        Int32 B = picture.GetPixel(e.X, e.Y).B;
        lbPixelValue.Text = "R:" + R + " G:" + G + " B:" + B;
        lbCoordinates.Text = String.Format("X: {0}; Y: {1}", e.X, e.Y);
    }
    else
    {
        lbPixelValue.Text = "";
        lbCoordinates.Text = "";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      相关资源
      最近更新 更多