-2

I know How to convert a PNG image to grayscale and without losing the transparency on C#, how to do it on Lua or cpp?

Ranoiaetep
  • 5,872
  • 1
  • 14
  • 39
Emoji
  • 101
  • 3
  • In the unlikely event that the library you're using doesn't have a built-in filter for this, the formula is trivial. Please show the code you're having trouble with. – stark Aug 06 '20 at 01:43

1 Answers1

0

PNG is a compressed format so you can't load that without some sort of library. BMP is significantly easier to load into memory, for example: https://bitbucket.org/itraykov/utils/src/master/io/bmp.lua

Now as for your original question how to convert color to black and white, the easiest way is to use the RGB average:

local r, g, b = getColor()
local bw = (r + g + b)/3
setColor(bw, bw, bw)

Of course you need to change getColor/setColor depending on the library that you are using. Additional checks are necessary for images with transparency or an alpha channel.

2dengine
  • 89
  • 1
  • 3