请教--如何获取图像某点的RGB值?

lfandlf 2003-08-06 04:04:05
rt
...全文
194 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzwu 2003-08-16
  • 打赏
  • 举报
回复
RGB三个分量存放在显卡的色彩查找表(CLUT)寄存器中,在DOS下完全可以直接从中取出来.
但在Windows下,一般用不到,也不容易,直接访问硬件的寄存器.

zzwu 2003-08-15
  • 打赏
  • 举报
回复
以上我说的是索引模式下的GetPixel(x,y).
zzwu 2003-08-15
  • 打赏
  • 举报
回复
GetPixel(x,y)只能得到逻辑色, 其值为0-255, 而提问者要的是R,G,B三个分量的值.



realizedream 2003-08-15
  • 打赏
  • 举报
回复
只获取少量点的颜色的话,C#可以用bmp.GetPixel(x,y)
大量的话,需要用到不安全代码:指针
lfandlf 2003-08-15
  • 打赏
  • 举报
回复
RGB value
gaxlin 2003-08-15
  • 打赏
  • 举报
回复
在photoshop下点击调色板可以得到
gong_chen 2003-08-15
  • 打赏
  • 举报
回复
问题提的模糊!!!
jerrya 2003-08-06
  • 打赏
  • 举报
回复
如果是图像,c#中更简单
//获取abc.bmp中(10,10)的颜色
Bitmap bmp=Image.FromFile("abc.bmp");
Color color=bmp.GetPixel(10,10);
jerrya 2003-08-06
  • 打赏
  • 举报
回复
c#代码:
[DllImport("user32")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32")]
public static extern int GetCursorPos(ref Point lpPoint);
[DllImport("gdi32")]
public static extern int GetPixel(IntPtr hdc,int x,int y);

private void timer1_Tick(object sender, System.EventArgs e)
{
int result;
int a;
Point p=new Point(0,0);
result=GetCursorPos(ref p);
label15.Text="X="+p.X.ToString();
label16.Text="Y="+p.Y.ToString();

a=GetPixel(GetDC((IntPtr)null),p.X,p.Y);
label17.Text="COLOR="+a.ToString("X6");
char[] r=new Char[2];
r[0]=a.ToString("X6")[4];
r[1]=a.ToString("X6")[5];
string sr=new string(r);

r[0]=a.ToString("X6")[2];
r[1]=a.ToString("X6")[3];
string sg=new string(r);

r[0]=a.ToString("X6")[0];
r[1]=a.ToString("X6")[1];
string sb=new string(r);

int ir=Int32.Parse(sr,System.Globalization.NumberStyles.HexNumber);
int ig=Int32.Parse(sg,System.Globalization.NumberStyles.HexNumber);
int ib=Int32.Parse(sb,System.Globalization.NumberStyles.HexNumber);

panel1.BackColor=Color.FromArgb(ir,ig,ib);
}
寻开心 2003-08-06
  • 打赏
  • 举报
回复
你的图象在那里放着呢?
如果在屏幕上,则是pDC->GetPixel()
CDC::GetPixel
COLORREF GetPixel( int x, int y ) const;

如果是文件,则要根据格式进行转换了

4,499

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧