Apply grayscale effect to Image using NDK(C/C++) in Android

ε祈祈猫儿з 提交于 2019-12-02 08:20:28

To obtain an image in grayscale, each pixel should have the same amount of red, green and blue

Maybe use the red component and affect it to both green and blue in your grayline computation

or use the formula (R+G+B)/3 = Gray

Negative images are normally obtained by by shifting each component :

NegR = 255 - grayR

and so on

So you could try to compute grayscal[x] = (255 - 0.3*line[x]) + ...

Edit for brightness: To obtain better brightness, try to add a fixed amount to your grayscale computation:

G += Bness;

Here it seems that Bness should be negative as long as you are going from 255(black) to 0(white) for some strange reason. You want to put a down limit to not go under 0 for your grascale value, then try :

G = max(0, G+Bness);

I recommend something like Bness = -25

Edit implementation brightness:

// Declare a global variable for your brightness - outside your class
static uint8_t bness = -25;

// In your grayscale computation function
for y...
 for x...
  grayscale[x] = ( (255-0.3*line[x].red) + ..... ) /3 ;
  int16_t gBright = grayscale[x] + bness;
  grayscale[x] = MAX( 0, gBright );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!