C#getpixel()不返回正确的值。 [英] C# getpixel() don't return correct value.

查看:489
本文介绍了C#getpixel()不返回正确的值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用灰色图像,getpixel()命令应该给我黑色区域的低数字和白色区域的高值。但是不要为我工作,并给我每个地区不正确的价值。



例如在一些白色区域,这个代码给我1号(与黑色有关)在一些黑色区域给我150或更多。



任何人都可以帮助我??



我尝试了什么:



我在dotpatial而不是picturebox中使用此代码:



I use a gray image that getpixel() command should give me the low number for black region and high value for white region. But don't work finely for me and give me incorrect value for every region.

For example in some white region this code give me number 1(related to black) and in the some black region give me 150 or more.

ANYONE CAN HELP ME??

What I have tried:

I use this code in dotspatial instead of picturebox:

public partial class formMain : Form
{

    Bitmap b = new Bitmap(@"F:\Hrit1\MSG1MostO.bmp");

    private void mapMain_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {

        Coordinate c= mapMain.PixelToProj(new System.Drawing.Point(e.X , e.Y ));

        int pixel = Convert.ToInt32(c.X);
        int line = Convert.ToInt32(c.Y);
        if (line < 0 || pixel < 0 || line > 850 || pixel > 1145)
        {
            line = 0;
            pixel = 0;
        }

        Color col = b.GetPixel(pixel, line);

        textBox1.Text = col.ToString();

}
  }

推荐答案

GetPixel( )返回颜色结构( System.Drawing) [ ^ ]。对于灰度图像,所有RGB分量将具有相同的值。所以使用 R G B 中的一个>获得强度的属性。返回的值是字节其中0是黑色,255是白色。
GetPixel() returns a Color Structure (System.Drawing)[^]. With gray scale images all RGB components will have the same value. So use one of the R, G, and B properties to get the intensity. The returned value is a byte where 0 is black and 255 is white.


这篇关于C#getpixel()不返回正确的值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆