简体   繁体   English

用OpenGL读取图像字节数组

[英]Reading image byte array with OpenGL

I have a bitmap image that is currently represented as a byte array (could be YCrCb or RGB). 我有一个位图图像,当前表示为字节数组(可以是YCrCb或RGB)。 Is there a function build in to OpenGL that will allow me to looks at individual pixels from this byte array? OpenGL中有内置的函数,可以让我查看此字节数组中的单个像素吗?

I know that there is the function glReadPixels but I don't need to be reading from the frame buffer if I've already got the data. 我知道有功能glReadPixels,但是如果我已经有数据,则不需要从帧缓冲区中读取。

If not, is there an alternative way to do this in C++? 如果没有,是否有其他方法可以在C ++中做到这一点?

OpenGL is a drawing API, not some kind of all purpose graphics library – The 'L' in OpenGL means should be read as Layer, not library. OpenGL是一种绘图API,而不是某种通用图形库– OpenGL中的“ L” 表示 应该读作Layer,而不是库。

That being said: If you know the dimensions of the byte array, and the data layout, then it is trivial to fetch individual pixels. 话虽这么说:如果您知道字节数组的大小以及数据布局,那么获取单个像素很简单。

pixel_at(x,y) = data_byte_array[row_stride * y + pixel_stride * x]

in a tightly packed format 紧密包装

pixel_stride = bytes_per_pixel
row_stride = width * pixel_stride

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM