5

I am looking to work with PNG format inside of either C++ or C#. I can't find any documentation on how to convert a PNG into a 2D array of bytes/floats which represent the colors on the image.

What I want to achieve:

  • Load Png to array [Width*Height]
  • Use PNG as a texture inside of a game

If someone could supply me with any documentation, source code or a C#/C++ library/dll that would be great.

Preferrably as C++ and without using any Windows specific library.

default
  • 11,485
  • 9
  • 66
  • 102
Haydn Trigg
  • 105
  • 1
  • 6

3 Answers3

4

Use libpng, the official PNG library.

Specifically, this page has all of the information on how to open and read.

David Pfeffer
  • 38,869
  • 30
  • 127
  • 202
1

For documentation on anything "standard" thing which is widely used, Wikipedia is usually the best first stop. From there you can either read the Wikipedia article, or skip right to External Links section.

For C# code, see for example: Reading a PNG image file in .Net 2.0 . As far as I can tell, it's old enough to be part of the ECMA-standardized version of C#, so should be available also on Mono.

Community
  • 1
  • 1
hyde
  • 60,639
  • 21
  • 115
  • 176
1

In C, libpng is the canonical way. In C#, you can try PngCs.

leonbloy
  • 73,180
  • 20
  • 142
  • 190