使用vs2008 c#通过(x,y)simultan获取像素值 [英] get pixel value by(x,y) simultan with vs2008 c#

查看:63
本文介绍了使用vs2008 c#通过(x,y)simultan获取像素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在使用C#和GDI +的虚拟对象的图像处理-第1部分-每个像素过滤器中找到了此代码 [^ ]

我发现我听不懂代码,这里的代码是:

public static bool Invert(Bitmap b)
{
    // GDI+ still lies to us - the return format is BGR, NOT RGB. 

    BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), 
    ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); 
    int stride = bmData.Stride; 
    System.IntPtr Scan0 = bmData.Scan0; 
    unsafe 
    { 
        byte * p = (byte *)(void *)Scan0;
        int nOffset = stride - b.Width*3; 
        int nWidth = b.Width * 3;
        for(int y=0;y < b.Height;++y)
        {
            for(int x=0; x < nWidth; ++x )
            {                                       
                p[0] = (byte)(255-p[0]);    // Here I want to get by pixel(x,y)
                ++p;                        // position simultaneously for exp:
                                            // result= 
                                            // pixel(0,0)+pixel(1,0)+pixel(2,0)
                                            // +pixel(0,1)+pixel(1,1)+ pixel(2,1)
                                            // +pixel(0,2)+pixel(1,2)+ pixel(2,2)
                                            // result=result/9;
                                            

            }           
            p += nOffset;                   //for what this function "p+=nOffset"?
        }                                   //I try to disable it and still work
    }
    b.UnlockBits(bmData);
    return true;
}



在这里,我想同时获得exp的pixel(x,y)位置:
结果=像素(0,0)+像素(1,0)+像素(2,0)+像素(0,1)+像素(1,1)+像素(2,1)+像素(0,2) + pixel(1,2)+ pixel(2,2)result = result/9;
怎么做?

而且比起我不理解"p + = nOffset;",我尝试禁用它并仍在运行.请向我解释?

谢谢:D

解决方案

不要将其发布在问题与答案"下-如果您从文章中获得了代码,则在此处有一个新消息"按钮该文章的底部,这将导致向作者发送电子邮件.然后会通知他们您希望与他们交谈.
将其发布到此处依赖于他们的"drop by"并意识到它是针对他们的.

提醒您,我不认为您会获得通用的向我解释这一点"的帮助-您最好通过调试器运行gthis并观察会发生什么-毕竟很明显.

Hello, I found this code in Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^]

I found I can''t understand code, here this code:

public static bool Invert(Bitmap b)
{
    // GDI+ still lies to us - the return format is BGR, NOT RGB. 

    BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), 
    ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); 
    int stride = bmData.Stride; 
    System.IntPtr Scan0 = bmData.Scan0; 
    unsafe 
    { 
        byte * p = (byte *)(void *)Scan0;
        int nOffset = stride - b.Width*3; 
        int nWidth = b.Width * 3;
        for(int y=0;y < b.Height;++y)
        {
            for(int x=0; x < nWidth; ++x )
            {                                       
                p[0] = (byte)(255-p[0]);    // Here I want to get by pixel(x,y)
                ++p;                        // position simultaneously for exp:
                                            // result= 
                                            // pixel(0,0)+pixel(1,0)+pixel(2,0)
                                            // +pixel(0,1)+pixel(1,1)+ pixel(2,1)
                                            // +pixel(0,2)+pixel(1,2)+ pixel(2,2)
                                            // result=result/9;
                                            

            }           
            p += nOffset;                   //for what this function "p+=nOffset"?
        }                                   //I try to disable it and still work
    }
    b.UnlockBits(bmData);
    return true;
}



Here I want to get by pixel(x,y) position simultaneously for exp:
result= pixel(0,0)+pixel(1,0)+pixel(2,0)+pixel(0,1)+pixel(1,1)+ pixel(2,1)+pixel(0,2)+pixel(1,2)+ pixel(2,2)result=result/9;
How to do it?

and than I don''t understand with "p += nOffset;", I try disable it and still running. please explain to me?

thanks :D

解决方案

Don''t post this under Questions & Answers - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.

Mind you, I don''t think you will get much help with a generic "explain this to me" - you might be better off runnin gthis through teh debugger and watching what happens - it is pretty obvious, after all.


这篇关于使用vs2008 c#通过(x,y)simultan获取像素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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