本文介绍了如何通过cimg获得rgb值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CImg<unsigned char> src("image.jpg");
int width = src.width();
int height = src.height();
unsigned char* ptr = src.data(10,10); 

如何从<$获得 rgb c $ c> ptr ?

How can I get rgb from ptr?

推荐答案

来自 - 第34页的第6.13节和第120页的第8.1.4.16节 - 看起来像数据方法可以采用四个参数:x,y,z和c:

From the CImg documentation -- section 6.13 on page 34, and section 8.1.4.16 on page 120 -- it looks like the data method can take four arguments: x, y, z, and c:

T* data(const unsigned int x, const unsigned int y = 0, 
        const unsigned int z = 0, const unsigned int c = 0)

...其中 c 是指颜色通道。我猜测如果你的图像确实是一个RGB图像,那么对于 c 使用0,1或2的值将为你提供红色,绿色和蓝色组件在给定的 x,y 位置。

...where c refers to the color channel. I'm guessing that if your image is indeed an RGB image, then using values of 0, 1, or 2 for c will give you the red, green, and blue components at a given x, y location.

例如:

unsigned char *r = src.data(10, 10, 0, 0);
unsigned char *g = src.data(10, 10, 0, 1);
unsigned char *b = src.data(10, 10, 0, 2);

(但这只是猜测!)

编辑:

看起来CImg的运营商()也以类似的方式运作:

It looks like there's also an operator() for CImg that works in a similar manner:

unsigned char r = src(10, 10, 0, 0);

这篇关于如何通过cimg获得rgb值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 00:27