| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 832 人关注过本帖
标题:像素值
只看楼主 加入收藏
ghl2312
Rank: 4
等 级:业余侠客
威 望:2
帖 子:208
专家分:226
注 册:2008-7-10
结帖率:100%
收藏
 问题点数:0 回复次数:5 
像素值
如何获取图象中某点的像素值,如想得到一张600*800的图片中(200,300)这点的像素值,应该怎么做?
搜索更多相关主题的帖子: 像素 图象 获取 
2008-08-15 09:38
ghl2312
Rank: 4
等 级:业余侠客
威 望:2
帖 子:208
专家分:226
注 册:2008-7-10
收藏
得分:0 
我自己顶一下!
2008-08-15 11:44
ghl2312
Rank: 4
等 级:业余侠客
威 望:2
帖 子:208
专家分:226
注 册:2008-7-10
收藏
得分:0 
就没人会?~天呐~
2008-08-18 08:18
wzg0319
Rank: 5Rank: 5
等 级:职业侠客
帖 子:68
专家分:305
注 册:2007-9-12
收藏
得分:0 
沒看懂题,说错了,不好意思
  你可以用API函數做..這是我剛做的一個,你看看.CODE如下:
   [DllImport("user32.dll")]
        static extern IntPtr GetDC(IntPtr hwnd);

        [DllImport("user32.dll")]
        static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);

        [DllImport("gdi32.dll")]
        static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);

        static public System.Drawing.Color GetPixelColor(int x, int y)
        {
            IntPtr hdc = GetDC(IntPtr.Zero);
            uint pixel = GetPixel(hdc, x, y);
            ReleaseDC(IntPtr.Zero, hdc);
            Color color = Color.FromArgb((int)(pixel & 0x000000FF),
            (int)(pixel & 0x0000FF00) >> 8,
            (int)(pixel & 0x00FF0000) >> 16);
            return color;
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            textBox1.Text = e.X.ToString();//坐標x值
            textBox2.Text = e.Y.ToString();//坐標y值
            richTextBox1.Text=GetPixelColor(e.X, e.Y).ToString();
            textBox3.Text = checkcolor(richTextBox1.Text.Trim(),"R=");//R值
            textBox4.Text = checkcolor(richTextBox1.Text.Trim(), "G=");//G值
            textBox5.Text = checkcolor(richTextBox1.Text.Trim(), "B=");//B值
            richTextBox1.Text = "該點的像數值是: R=" + textBox3.Text.Trim() + " G=" + textBox4.Text.Trim() + " B=" + textBox5.Text.Trim();
        }

        private string checkcolor(string temp,string filed)
        {
            string b = string.Empty;
            if (filed == "R=")
            {
                 b = temp.Trim().Substring(temp.Trim().IndexOf(filed) + filed.Length, temp.Trim().IndexOf("G=") - (temp.Trim().IndexOf(filed) + filed.Length+2));
            }
            if (filed == "G=")
            {
                 b = temp.Trim().Substring(temp.Trim().IndexOf(filed) + filed.Length, temp.Trim().IndexOf("B=") - (temp.Trim().IndexOf(filed) + filed.Length+2));
            }
            if (filed == "B=")
            {
                b = temp.Substring(temp.IndexOf(filed) + filed.Length, temp.Length - (temp.IndexOf(filed) + filed.Length+1));
            }
           
            return b;
        }

[[it] 本帖最后由 wzg0319 于 2008-8-18 10:51 编辑 [/it]]
2008-08-18 09:13
liang4571231
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-8-16
收藏
得分:0 
这里有个帖子,和你问的问题是一样的,你可以看下,我是看不懂
http://www.
2008-08-18 09:17
fjfhnui
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2007-6-18
收藏
得分:0 
Color pixelColor = image1.GetPixel(x, y);
                Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
                image1.SetPixel(x, y, newColor);
2008-08-24 03:38
快速回复:像素值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011908 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved