图像处理帮助 [英] help for image processing

查看:53
本文介绍了图像处理帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

首先我说,对不起我的语言不好.
然后,我在c#中的图像处理中遇到了问题.
我得到了带有GetPixel函数的argb.
但这会返回错误的颜色吗?

请帮我解决这个问题.


谢谢

mohammad.r.khaliliazar
[已删除]

[edit]电子邮件已删除:除非您确实喜欢垃圾邮件,否则切勿在任何公共论坛上发布您的电子邮件! -OriginalGriff [/edit]



感谢您的帮助originalgriff
这是我的代码:

Hello,

First I say , excuse me about my language is not good.
And then, I have a problem in image processing in c#.
I get the argb, with GetPixel function.
But this return wrong color?

plz help me to this.


thanks

mohammad.r.khaliliazar
[DELETED]

[edit]Email deleted: Never post your email to any public forum, unless you really like spam! - OriginalGriff[/edit]



thanks for your help originalgriff
it''s my code:

Bitmap myBitmap;
x=e.X;
y = e.Y;
Color color = myBitmap.GetPixel(x, y);
label1.Text="Color Of "+x.ToString()+" , "+y.ToString()+" is : "+color.Name.ToString()+"    "+color.ToString();

Color color2 = Color.FromArgb(color.R, color.B, color.G);
panel1.BackColor = color2;

推荐答案

返回错误的颜色"是什么意思?如果没有您的代码,很难知道发生了什么,但是:

What do you mean it "returns the wrong colour"? Without your code it is difficult to tell what is going on, but this:

Bitmap red = (Bitmap) Bitmap.FromFile(@"F:\Temp\Red.bmp");
Bitmap green = (Bitmap) Bitmap.FromFile(@"F:\Temp\Green.bmp");
Bitmap blue = (Bitmap) Bitmap.FromFile(@"F:\Temp\Blue.bmp");
Color c = red.GetPixel(0, 0);
int argb = c.ToArgb();
Console.WriteLine("{0:X8}", argb);
c = green.GetPixel(0, 0);
argb = c.ToArgb();
Console.WriteLine("{0:X8}", argb);
c = blue.GetPixel(0, 0);
argb = c.ToArgb();
Console.WriteLine("{0:X8}", argb);

产生:

FFFF0000
FF00FF00
FF0000FF

这是我期望的.如果这不是您要执行的操作,请编辑您的问题并提供相关的代码片段.


更新:

Which is what I would expect. If this is not what you are doing, please edit your question and provide a relevant code fragment.


UPDATE:

Bitmap myBitmap;
x=e.X;
y = e.Y;
Color color = myBitmap.GetPixel(x, y);
label1.Text="Color Of "+x.ToString()+" , "+y.ToString()+" is : "+color.Name.ToString()+"    "+color.ToString();

Color color2 = Color.FromArgb(color.R, color.B, color.G);
panel1.BackColor = color2;

如果这是您的准确代码,那么我就不会感到惊讶它无法正常工作-实际上,它应该会给您带来错误.

首先:您似乎没有将myBitmap 分配给任何东西:这意味着myBitmap.GetPixel调用应为您提供Null Reference Exception.
其次:为什么要从Color 的Argb值创建Color(但忽略Alpha透明度)?

我假设您正在鼠标单击事件处理程序或类似程序中使用此代码?
如果是这样,那么您需要获取鼠标上方的控件的图形上下文,并从中获取像素信息-这不是一件容易的事,但是有一个示例

If that is your exact code, then I''m not surprised it doesn''t work properly - in fact, it should give you errors.

Firstly: You don''t appear to be assigning myBitmap to anything: which means that the myBitmap.GetPixel call should give you a Null Reference Exception.
Secondly: Why are you creating a Color from the Argb value of a Color (but ignoring the Alpha transparency)?

I assume you are using this code in a mouse click event handler or similar?
If so, then you need to get the graphics context for the control the mouse if over and get the pixel information from that - not a trivial job, but there is an example here.[^]


您说您从对GetPixel()的调用中获得了"argb",但GetPixel返回了Color结构. />
您还说它返回错误的颜色.这是什么意思?你怎么知道它是错误的颜色?

没有看到您的代码,很难回答您的问题.

请编辑您的问题(使用绿色的改善问题"小部件并添加您的代码.请不要忘记在代码中加上< pre lang ="cs"> 您的代码在此处</pre>标记.
You say that you get the ''argb'' from a call to GetPixel() but GetPixel returns a Color structure.

You also say that it returns the wrong color. What does this mean? How do you know it is the wrong color?

Without seeing your code, it is very difficult to answer your question.

Please edit your question (use the green ''Improve question'' widget and add your code. Please don''t forget to surround your code with <pre lang="cs">your code goes here</pre> tags.


不要使用GetPixel,它的速度很慢.请阅读我的图像处理文章以了解如何正确执行
Don''t use GetPixel, it''s slow. Read my image processing articles to see how to do it properly


这篇关于图像处理帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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