C++用户使用eekg选择的像素的RGB值
我需要创建一个程序来加载 .raw 图像(通用 100x100 图像),要求用户选择范围内的 (x, y) 坐标,并使用eekg 显示所述像素的红色、绿色和蓝色值功能。我不知道如何从像素获取 RGB 值。我已经浏览了到目前为止我们所涵盖的教科书的每一章,并且没有任何关于检索 RGB 值的内容。
询问坐标并在超出范围时给出错误消息的代码工作正常。只有当我尝试编写使用eekg/获取rgb值的代码时,我才会遇到麻烦。我在网站上查看了不同的问题,这里有很好的信息,但我没有看到任何使用eekg来获取rgb值的答案。
我并不是在寻找任何人为我生成代码,只是在寻找一些指导并推动正确的方向。
loc = (y * 100 + x) * 3; // code given by professor with 100 being the width of the image
imageRaw.seekg(loc, ios::beg);
然后我就不知所措了。
任何帮助将不胜感激。
I need to create a program that loads a .raw image (generic 100x100 image), asks the user to select an (x, y) coordinate within the range, and display the red, green, and blue values for said pixel using the seekg function. I'm at a loss as to how to get the rgb values from the pixel. I've gone through every chapter of the textbook that we've covered so far, and there is nothing about retreiving rgb values.
The code asking for the coordinates and giving an error message if outside the range is working fine. Only when I try to come up with the code for using seekg/getting the rgb values am I running in to trouble. I've looked at different questions on the site, and there is good information here, but I've not see any answers using seekg in order to get the rgb values.
I'm not looking for anyone to produce the code for me, just looking for some guidance and a push in the right direction.
loc = (y * 100 + x) * 3; // code given by professor with 100 being the width of the image
imageRaw.seekg(loc, ios::beg);
And then I'm at a loss.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从那里,您可能需要读取三个字节,它们代表红色、绿色和蓝色值。你没有告诉我们足够的信息来确定订单;绿色几乎总是在中间,但 RGB 和 BGR 都相当常见。
从实际角度来看,对于这种尺寸的图片,您通常根本不想使用eekg。您将整个图像读入内存,并在存储数据的向量(或数组,如果您坚持的话)中查找值。
From there, you probably need to read three bytes, which will represent the red, green, and blue values. You haven't told us enough to be sure of the order; green is almost always in the middle, but RGB and BGR are both fairly common.
From a practical viewpoint, for a picture of this size you don't normally want to use seekg at all though. You'd read the entire image into memory, and lookup the values in the vector (or array, if you insist) that stores the data.