- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建并加载了这张图片:
int x, y, comps;
unsigned char* data = stbi_load(".//textures//heightMapTexture.png", &x, &y, &comps, 1);
现在,我如何获得此图像的某个像素的 RGB?
最佳答案
您正在使用每 channel 8 位接口(interface)。此外,您只请求一个 channel (给 stbi_load
的最后一个参数)。仅请求一个 channel ,您将无法获得 RGB 数据。
如果您使用 rgb 图像,您可能会在 comps
中得到 3 或 4 个,并且您希望在最后一个参数中至少有 3 个。
stbi_load 返回的 data
缓冲区将包含 8 位 * x * y * channelRequested 或 x * y * channelCount 字节。您可以这样访问 (i, j) 像素信息:
unsigned bytePerPixel = channelCount;
unsigned char* pixelOffset = data + (i + x * j) * bytePerPixel;
unsigned char r = pixelOffset[0];
unsigned char g = pixelOffset[1];
unsigned char b = pixelOffset[2];
unsigned char a = channelCount >= 4 ? pixelOffset[3] : 0xff;
这样您就可以获得 RGB(A) 每像素数据。
关于c++ - 获取 stb_image 中某个像素的 RGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48235421/
我一直在用 C++ 开发一个新项目,使用 GLFW 作为 OpenGL 包装器,并使用 stb_image.h 工具加载图像。 我使用以下代码片段加载图像: this->width = width;
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我正在使用 stb_image.c 将数据字节加载到 opengl。但是,当我尝试使用 alpha channel 加载 png 文件时,我遇到了一个问题 现在白色区域应该是透明的,虽然它只清除了一小
我创建并加载了这张图片: int x, y, comps; unsigned char* data = stbi_load(".//textures//heightMapTexture.png", &
我想将这张图片加载到二维纹理中,然后将其绘制到屏幕上。主要问题是将图片加载到纹理变量中。以下代码输出正确的宽度和高度以及 rgba,但我如何将数据放入 3d 纹理中。 #include #inclu
stb_image 似乎支持 idct 和 ycbcr->rgb 转换操作的插件 SIMD 实现,这在加载 jpeg 文件时占用了大部分时间。查看 STBI_SIMD 背后的代码,很明显这段代码实际上
我尝试加载的图像在呈现时旋转了 90 度。我使用的是“加载时垂直翻转图像”,但渲染纹理时,图像会旋转 90 度。 我尝试更改索引和 tex 坐标,但没有用。 //Mesh struct Mesh me
我已经打开了 bmp 文件(一个 channel 灰度)并将每个像素颜色存储在一个新行中作为十六进制。在对数据进行一些处理后(不是这个问题的重点),我需要从我的数据中导出一个 bmp 图像。如何加载文
我正在研究 OpenGL 驱动的 2d 引擎。 我正在使用 stb_image 加载图像数据,以便创建 OpenGL 纹理。我知道 OpenGL 的 UV 原点是左下角,我还打算在该空间中为我的屏幕空
我想使用 stb_image 库,作者已经把它放到了一个非常大的头文件中。要使用该库,文档告诉我将这两行添加到我的代码中。 #define STB_IMAGE_IMPLEMENTATION #incl
我已经下载了 stb_image.h ( https://github.com/nothings/stb ) 并包含在我想使用它的 .cpp 文件中。 然后我使用函数加载图像 image_data =
我正在使用 stb_image 加载一个 32 位 PNG 文件 (RGBA),并使用它创建一个 OpenGL 纹理。 它适用于 24 位 PNG 文件(没有 alpha channel ),但是当我
我是一名优秀的程序员,十分优秀!